// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.assets.service.impl;

import com.liuxinlong.common.AosException;
import com.liuxinlong.common.SnowFlake;
import com.liuxinlong.constant.ThreadLocalConstants;
import com.liuxinlong.constant.TimeFormatConstants;
import com.liuxinlong.enums.AssetsCategoryTypeEnum;
import com.liuxinlong.enums.AssetsTypeEnum;
import com.liuxinlong.enums.InvestmentCapitalEnum;
import com.liuxinlong.enums.InvestmentConfigTypeEnum;
import com.liuxinlong.enums.InvestmentExpensesEnum;
import com.liuxinlong.enums.InvestmentLossRateEnum;
import com.liuxinlong.enums.InvestmentParEnum;
import com.liuxinlong.enums.InvestmentTurnoverEnum;
import com.liuxinlong.enums.ReturnCodes;
import com.liuxinlong.modules.assets.dto.CalculateDataDto;
import com.liuxinlong.modules.assets.service.AssetsInvestmentService;
import com.liuxinlong.modules.dao.AssetsInvestmentDao;
import com.liuxinlong.modules.dao.AssetsInvestmentInputDao;
import com.liuxinlong.modules.dao.AssetsInvestmentLossRateDao;
import com.liuxinlong.modules.dao.AssetsInvestmentOtherExpensesDao;
import com.liuxinlong.modules.dao.AssetsInvestmentParDao;
import com.liuxinlong.modules.dao.AssetsInvestmentProductDao;
import com.liuxinlong.modules.dao.AssetsInvestmentTurnoverDao;
import com.liuxinlong.modules.dao.InvestmentCommonConfigDao;
import com.liuxinlong.modules.dao.InvestmentConfigDao;
import com.liuxinlong.modules.dao.ProjectDao;
import com.liuxinlong.modules.dao.UserDao;
import com.liuxinlong.modules.entity.AssetsInvestment;
import com.liuxinlong.modules.entity.AssetsInvestmentCommonConfig;
import com.liuxinlong.modules.entity.AssetsInvestmentConfig;
import com.liuxinlong.modules.entity.InvestmentInput;
import com.liuxinlong.modules.entity.InvestmentLossRate;
import com.liuxinlong.modules.entity.InvestmentOtherExpenses;
import com.liuxinlong.modules.entity.InvestmentProduct;
import com.liuxinlong.modules.entity.InvestmentTurnover;
import com.liuxinlong.modules.entity.User;
import com.liuxinlong.utils.ObjectUtils;
import com.liuxinlong.utils.ThreadlocalUtils;
import com.liuxinlong.utils.TimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 固资项目管理业务接口层实现
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2024-09-04
 */
@Service
@Slf4j
public class AssetsInvestmentServiceImpl implements AssetsInvestmentService {

    @Autowired
    private AssetsInvestmentDao assetsInvestmentDao;

    @Autowired
    private UserDao userDao;

    @Autowired
    private AssetsInvestmentProductDao assetsInvestmentProductDao;

    @Autowired
    private AssetsInvestmentInputDao assetsInvestmentInputDao;

    @Autowired
    private AssetsInvestmentOtherExpensesDao assetsInvestmentOtherExpensesDao;

    @Autowired
    private AssetsInvestmentLossRateDao assetsInvestmentLossRateDao;

    @Autowired
    private AssetsInvestmentTurnoverDao assetsInvestmentTurnoverDao;

    @Autowired
    private AssetsInvestmentParDao investmentParDao;

    @Autowired
    private InvestmentConfigDao investmentConfigDao;

    @Autowired
    private InvestmentCommonConfigDao investmentCommonConfigDao;

    @Autowired
    private ProjectDao projectDao;

    @Override
    public List<Map<String, Object>> pageAssetsInvestmentInfo(Map<String, Object> queryParam) {
        List<AssetsInvestment> originalList = assetsInvestmentDao.pageAssetsInvestmentInfo(queryParam);
        int startNum = (int) queryParam.get("startNum");
        return completeResult(originalList, startNum);
    }

    @Override
    public int getAssetsInvestmentInfoCount(Map<String, Object> queryParam) {
        return assetsInvestmentDao.getAssetsInvestmentInfoCount(queryParam);
    }

    @Override
    public Map<String, Object> getAssetsInvestmentDetail(String id) {
        Map<String, Object> dataMap = new HashMap<>();
        // 基本信息
        AssetsInvestment basicData = assetsInvestmentDao.selectById(id);
        dataMap.put("basicData", basicData);

        // 产品信息
        Map<String, Object> queryParam = new HashMap<>();
        queryParam.put("investmentId", id);
        queryParam.put("startNum", 0);
        queryParam.put("pageSize", 10000);
        List<InvestmentProduct> productList = assetsInvestmentProductDao.pageInvestmentProductInfo(queryParam);
        List<Map<String, Object>> newProductList = new ArrayList<>();
        List<Map<String, Object>> replaceProductList = new ArrayList<>();
        Map<String, Map<String, String>> commonMap = investmentCommonConfigDao.getCommonConfigMap();
        for (InvestmentProduct product : productList) {
            Map<String, Object> productMap = ObjectUtils.object2Map(product);
            productMap.put("channelName", commonMap.containsKey(product.getChannel()) ?
                    commonMap.get(product.getChannel()).get("name") : "");
            productMap.put("categoryName", commonMap.containsKey(product.getCategory()) ?
                    commonMap.get(product.getCategory()).get("name") : "");
            productMap.put("brandName", commonMap.containsKey(product.getBrand()) ?
                    commonMap.get(product.getBrand()).get("name") : "");
            BigDecimal salesTotal = BigDecimal.ZERO.add(new BigDecimal(product.getSalesOne()))
                    .add(new BigDecimal(product.getSalesTwo()))
                    .add(new BigDecimal(product.getSalesThree()))
                    .add(new BigDecimal(product.getSalesFour()))
                    .add(new BigDecimal(product.getSalesFive()));
            productMap.put("salesTotal", salesTotal);
            if (product.getType() == 1) {
                newProductList.add(productMap);
            } else if (product.getType() == 2) {
                replaceProductList.add(productMap);
            }
        }
        dataMap.put("newProductData", newProductList);
        dataMap.put("replaceProductData", replaceProductList);

        // 固资投入信息
        List<InvestmentInput> investmentInputList = assetsInvestmentInputDao.pageInvestmentInputInfo(queryParam);
        List<Map<String, Object>> investList = new ArrayList<>(investmentInputList.size());
        for (InvestmentInput investmentInput : investmentInputList) {
            Map<String, Object> inputInfo = ObjectUtils.object2Map(investmentInput);
            inputInfo.put("assetsTypeName", AssetsTypeEnum.getNameByValue(Integer.valueOf(investmentInput.getAssetsType())));
            investList.add(inputInfo);
        }
        dataMap.put("investData", investList);

        // 其他一次性支出信息
        List<InvestmentOtherExpenses> otherList = assetsInvestmentOtherExpensesDao.pageInvestmentOtherExpensesInfo(queryParam);
        List<Map<String, Object>> expensesList = new ArrayList<>(otherList.size());
        for (InvestmentOtherExpenses other : otherList) {
            Map<String, Object> expensesInfo = ObjectUtils.object2Map(other);
            expensesInfo.put("typeName", InvestmentExpensesEnum.getNameByValue(Integer.valueOf(other.getExpensesType())));
            expensesList.add(expensesInfo);
        }
        dataMap.put("expensesData", expensesList);

        // 损益费率信息
        List<InvestmentLossRate> lossRateList = assetsInvestmentLossRateDao.pageInvestmentLossRateInfo(queryParam);
        List<Map<String, Object>> lossList = new ArrayList<>(lossRateList.size());
        for (InvestmentLossRate lossRate : lossRateList) {
            Map<String, Object> lossInfo = ObjectUtils.object2Map(lossRate);
            lossInfo.put("rateName", InvestmentLossRateEnum.getNameByValue(lossRate.getRateType()));
            lossList.add(lossInfo);
        }
        dataMap.put("lossRateData", lossList);

        // 周转天数信息
        List<InvestmentTurnover> turnList = assetsInvestmentTurnoverDao.pageInvestmentTurnoverInfo(queryParam);
        List<Map<String, Object>> turnoverList = new ArrayList<>(turnList.size());
        for (InvestmentTurnover turnover : turnList) {
            Map<String, Object> turnInfo = ObjectUtils.object2Map(turnover);
            turnInfo.put("typeName", InvestmentTurnoverEnum.getNameByValue(turnover.getTurnoverType()));
            turnoverList.add(turnInfo);
        }
        dataMap.put("turnoverData", turnoverList);
        return dataMap;
    }

    @Transactional
    @Override
    public String addAssetsInvestmentInfo(CalculateDataDto calculateDataDto) {
        User currentUser = (User) ThreadlocalUtils.getCache(ThreadLocalConstants.USER_INFO);
        String currentTime = TimeUtils.getDate(TimeFormatConstants.YYYY_MM_DD_HH_MM_SS);
        String id = SnowFlake.nextIdStr();

        // 基本信息
        AssetsInvestment basicData = calculateDataDto.getBasicData();
        basicData.setId(id);
        basicData.setOperateTime(currentTime);
        basicData.setOperateUser(currentUser.getId());
        basicData.setCreateUser(currentUser.getId());
        basicData.setCreateTime(currentTime);
        basicData.setStatus(1);
        assetsInvestmentDao.insert(basicData);

        // 产品信息
        List<InvestmentProduct> productList = new ArrayList<>();
        List<InvestmentProduct> newProductList = calculateDataDto.getNewProductData();
        if (ObjectUtils.isEmpty(newProductList)) {
            throw new AosException(ReturnCodes.HTTP_PARAM_ERROR, "新产品信息不能为空！");
        }
        for (InvestmentProduct newProduct : newProductList) {
            newProduct.setType(1);
            newProduct.setId(SnowFlake.nextIdStr());
            newProduct.setInvestmentId(id);
            newProduct.setCreateUser(currentUser.getId());
            newProduct.setCreateTime(currentTime);
            productList.add(newProduct);
        }
        List<InvestmentProduct> replaceProductList = calculateDataDto.getReplaceProductData();
        for (InvestmentProduct replaceProduct : replaceProductList) {
            replaceProduct.setType(2);
            replaceProduct.setId(SnowFlake.nextIdStr());
            replaceProduct.setInvestmentId(id);
            replaceProduct.setCreateUser(currentUser.getId());
            replaceProduct.setCreateTime(currentTime);
            productList.add(replaceProduct);
        }
        assetsInvestmentProductDao.insertBatch(productList);

        // 固资投入
        List<InvestmentInput> investInputList = calculateDataDto.getInvestData();
        if (!ObjectUtils.isEmpty(investInputList)) {
            List<InvestmentInput> addInputList = new ArrayList<>();
            for (InvestmentInput investmentInput : investInputList) {
                investmentInput.setId(SnowFlake.nextIdStr());
                investmentInput.setInvestmentId(id);
                addInputList.add(investmentInput);
            }
            if (!ObjectUtils.isEmpty(addInputList)) {
                assetsInvestmentInputDao.insertBatch(addInputList);
            }
        }

        // 其他一次性支出
        List<InvestmentOtherExpenses> investExpensesList = calculateDataDto.getExpensesData();
        if (!ObjectUtils.isEmpty(investExpensesList)) {
            List<InvestmentOtherExpenses> addExpensesList = new ArrayList<>();
            for (InvestmentOtherExpenses expenses : investExpensesList) {
                expenses.setId(SnowFlake.nextIdStr());
                expenses.setInvestmentId(id);
                addExpensesList.add(expenses);
            }
            if (!ObjectUtils.isEmpty(addExpensesList)) {
                assetsInvestmentOtherExpensesDao.insertBatch(addExpensesList);
            }
        }

        // 损益费率
        List<InvestmentLossRate> lossRateList = calculateDataDto.getLossRateData();
        if (!ObjectUtils.isEmpty(lossRateList)) {
            List<InvestmentLossRate> addLossRateList = new ArrayList<>();
            for (InvestmentLossRate lossRate : lossRateList) {
                lossRate.setId(SnowFlake.nextIdStr());
                lossRate.setInvestmentId(id);
                addLossRateList.add(lossRate);
            }
            if (!ObjectUtils.isEmpty(addLossRateList)) {
                assetsInvestmentLossRateDao.insertBatch(addLossRateList);
            }
        } else {
            Map<String, Object> queryMap = new HashMap<>();
            queryMap.put("startNum", 0);
            queryMap.put("pageSize", 1000);
            queryMap.put("configType", InvestmentConfigTypeEnum.TYPE_LOSS.getValue() - 4);
            queryMap.put("configYear", TimeUtils.getYear());
            queryMap.put("configClass", basicData.getCategory());
            queryMap.put("status", 1);
            List<AssetsInvestmentConfig> lossConfigList = investmentConfigDao.pageInvestmentConfigInfo(queryMap);
            if (lossConfigList.isEmpty()) {
                throw new AosException(ReturnCodes.HTTP_PARAM_ERROR, "未配置损益费率！");
            }
            Map<String,Object> queryBrand = new HashMap<>();
            queryBrand.put("configType", InvestmentConfigTypeEnum.TYPE_BRAND.getValue());
            queryBrand.put("status", 1);
            queryBrand.put("startNum", 0);
            queryBrand.put("pageSize", 100);
            List<AssetsInvestmentCommonConfig> brandList = investmentCommonConfigDao.pageInvestmentCommonConfigInfo(queryBrand);
            Map<String,String> brandMap = new HashMap<>();
            for (AssetsInvestmentCommonConfig brandConfig: brandList) {
                brandMap.put(brandConfig.getId(),brandConfig.getConfigName());
            }
            List<InvestmentLossRate> addLossRateList = new ArrayList<>();
            for (InvestmentLossRateEnum item : InvestmentLossRateEnum.values()) {
                InvestmentLossRate dto = new InvestmentLossRate();
                dto.setId(SnowFlake.nextIdStr());
                dto.setRateType(item.getValue());
                dto.setInvestmentId(id);
                for (AssetsInvestmentConfig config: lossConfigList){
                    String value = item.getValue() == InvestmentLossRateEnum.SALES.getValue() ? config.getParamOne()
                            : item.getValue() == InvestmentLossRateEnum.SERVICE.getValue() ? config.getParamTwo()
                            : item.getValue() == InvestmentLossRateEnum.DIRECT.getValue() ? config.getParamThree()
                            : item.getValue() == InvestmentLossRateEnum.INDIRECT.getValue() ? config.getParamFour()
                            : item.getValue() == InvestmentLossRateEnum.ADVERTISING.getValue() ? config.getParamFive()
                            : item.getValue() == InvestmentLossRateEnum.ENGINEERING.getValue() ? config.getParamSix()
                            : item.getValue() == InvestmentLossRateEnum.PRODUCT.getValue() ? config.getParamSeven() : "0";
                    if (StringUtils.equals(brandMap.get(config.getConfigBrand()),"史密斯")) {
                        dto.setRateAmountSms(value);
                    } else  if (StringUtils.equals(brandMap.get(config.getConfigBrand()),"佳尼特")) {
                        dto.setRateAmountJnt(value);
                    }
                }
                addLossRateList.add(dto);
            }
            if (!ObjectUtils.isEmpty(addLossRateList)) {
                assetsInvestmentLossRateDao.insertBatch(addLossRateList);
            }
        }

        // 周转天数
        List<InvestmentTurnover> turnoverList = calculateDataDto.getTurnoverData();
        if (!ObjectUtils.isEmpty(turnoverList)) {
            List<InvestmentTurnover> addTurnoverList = new ArrayList<>();
            for (InvestmentTurnover turnover : turnoverList) {
                turnover.setId(SnowFlake.nextIdStr());
                turnover.setInvestmentId(id);
                addTurnoverList.add(turnover);
            }
            if (!ObjectUtils.isEmpty(addTurnoverList)) {
                assetsInvestmentTurnoverDao.insertBatch(addTurnoverList);
            }
        } else {
            Map<String, Object> queryMap = new HashMap<>();
            queryMap.put("startNum", 0);
            queryMap.put("pageSize", 1000);
            queryMap.put("configType", InvestmentConfigTypeEnum.TYPE_TURNOVER.getValue() - 4);
            queryMap.put("configClass", basicData.getCategory());
            queryMap.put("status", 1);
            List<AssetsInvestmentConfig> configList = investmentConfigDao.pageInvestmentConfigInfo(queryMap);
            if (configList.isEmpty()) {
                throw new AosException(ReturnCodes.HTTP_PARAM_ERROR, "未配置周转天数！");
            }
            AssetsInvestmentConfig configInfo = configList.get(0);
            List<InvestmentTurnover> addTurnoverList = new ArrayList<>();
            for (InvestmentTurnoverEnum item : InvestmentTurnoverEnum.values()) {
                InvestmentTurnover dto = new InvestmentTurnover();
                dto.setId(SnowFlake.nextIdStr());
                dto.setTurnoverType(item.getValue());
                dto.setInvestmentId(id);
                dto.setDays(item.getValue() == InvestmentTurnoverEnum.AR.getValue() ? Integer.parseInt(configInfo.getParamOne()) :
                        item.getValue() == InvestmentTurnoverEnum.INVENTORY.getValue() ? Integer.parseInt(configInfo.getParamTwo()) :
                                item.getValue() == InvestmentTurnoverEnum.AP.getValue() ? Integer.parseInt(configInfo.getParamThree()) : 0);
                addTurnoverList.add(dto);
            }
            if (!ObjectUtils.isEmpty(addTurnoverList)) {
                assetsInvestmentTurnoverDao.insertBatch(addTurnoverList);
            }
        }
        return id;
    }

    @Override
    @Transactional
    public String updateAssetsInvestmentInfo(CalculateDataDto calculateDataDto) {
        if (StringUtils.isEmpty(calculateDataDto.getId())) {
            return this.addAssetsInvestmentInfo(calculateDataDto);
        } else {
            return this.modifyInvestmentInfo(calculateDataDto);
        }
    }

    @Override
    public void deleteAssetsInvestmentInfo(String id) {

    }

    @Override
    @Transactional
    public Map<String, Object> addAssetsCalculationInfo(CalculateDataDto calculateDataDto) {
        String id;
        if (StringUtils.isEmpty(calculateDataDto.getId())) {
            id = addAssetsInvestmentInfo(calculateDataDto);
        } else {
            id = updateAssetsInvestmentInfo(calculateDataDto);
        }
        Map<String, Object> dataMap = calculate(calculateDataDto);
        AssetsInvestment basicData = assetsInvestmentDao.selectById(id);
        basicData.setStatus(2);
        assetsInvestmentDao.updateById(basicData);
        return dataMap;
    }

    @Override
    public Map<String, Object> getAssetsCalculationDetail(String id) {
        CalculateDataDto calculateDataDto = this.getCalculateData(id);
        return calculate(calculateDataDto);
    }

    @Override
    public void exportAssetsInvestment(Map<String, Object> queryParam, HttpServletResponse response) {

    }

    @Override
    public Map<String, Object> getProductConfigInfo(String category, String model, String channel, String brand) {
        Map<String, Object> dataMap = new HashMap<>();
        return dataMap;
    }

    /**
     * 补全数据
     *
     * @param originalList 原始数据
     * @param startNum     数据起始值
     * @return 补全数据列表
     */
    private List<Map<String, Object>> completeResult(List<AssetsInvestment> originalList, int startNum) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        Map<String, Map<String, String>> userMap = userDao.getUserMap();
        Map<String, Map<String, String>> projectMap = projectDao.getProjectMap();
        int sort = startNum + 1;
        for (AssetsInvestment assetsInvestment : originalList) {
            Map<String, Object> item = ObjectUtils.object2Map(assetsInvestment);
            item.put("sort", sort);
            item.put("operateUserName", userMap.containsKey(assetsInvestment.getOperateUser()) ?
                    userMap.get(assetsInvestment.getOperateUser()).get("name") : "");
            item.put("projectNo", projectMap.containsKey(assetsInvestment.getProjectId()) ?
                    projectMap.get(assetsInvestment.getProjectId()).get("financialSn") : "");
            resultList.add(item);
            sort++;
        }
        return resultList;
    }

    /**
     * 固资测算模型
     *
     * @param calculateDataDto 固资测算数据
     */
    private Map<String, Object> calculate(CalculateDataDto calculateDataDto) {
        Map<String, Object> dataMap = new HashMap<>();
        Map<String, Map<String, String>> commonMap = investmentCommonConfigDao.getCommonConfigMap();
        Map<String, Object> queryBrand = new HashMap<>();
        queryBrand.put("configType", InvestmentConfigTypeEnum.TYPE_BRAND.getValue());
        queryBrand.put("status", 1);
        queryBrand.put("startNum", 0);
        queryBrand.put("pageSize", 100);
        List<AssetsInvestmentCommonConfig> brandList = investmentCommonConfigDao.pageInvestmentCommonConfigInfo(queryBrand);
        Map<String, String> brandMap = new HashMap<>();
        for (AssetsInvestmentCommonConfig brandConfig : brandList) {
            brandMap.put(brandConfig.getId(), brandConfig.getConfigName());
        }
        // Margin
        Map<String, Object> marginMap = new HashMap<>();
        List<InvestmentProduct> newProductList = calculateDataDto.getNewProductData();
        List<Map<String, Object>> newProductMarginList = new ArrayList<>(newProductList.size());
        // invoicedSales
        BigDecimal invoicedSalesSmsNewOne = BigDecimal.ZERO;
        BigDecimal invoicedSalesSmsNewTwo = BigDecimal.ZERO;
        BigDecimal invoicedSalesSmsNewThree = BigDecimal.ZERO;
        BigDecimal invoicedSalesSmsNewFour = BigDecimal.ZERO;
        BigDecimal invoicedSalesSmsNewFive = BigDecimal.ZERO;
        BigDecimal invoicedSalesJntNewOne = BigDecimal.ZERO;
        BigDecimal invoicedSalesJntNewTwo = BigDecimal.ZERO;
        BigDecimal invoicedSalesJntNewThree = BigDecimal.ZERO;
        BigDecimal invoicedSalesJntNewFour = BigDecimal.ZERO;
        BigDecimal invoicedSalesJntNewFive = BigDecimal.ZERO;
        // Volume
        BigDecimal volumeSmsNewOne = BigDecimal.ZERO;
        BigDecimal volumeSmsNewTwo = BigDecimal.ZERO;
        BigDecimal volumeSmsNewThree = BigDecimal.ZERO;
        BigDecimal volumeSmsNewFour = BigDecimal.ZERO;
        BigDecimal volumeSmsNewFive = BigDecimal.ZERO;
        BigDecimal volumeJntNewOne = BigDecimal.ZERO;
        BigDecimal volumeJntNewTwo = BigDecimal.ZERO;
        BigDecimal volumeJntNewThree = BigDecimal.ZERO;
        BigDecimal volumeJntNewFour = BigDecimal.ZERO;
        BigDecimal volumeJntNewFive = BigDecimal.ZERO;
        // Cost
        BigDecimal costYSmsNewOne = BigDecimal.ZERO;
        BigDecimal costYSmsNewTwo = BigDecimal.ZERO;
        BigDecimal costYSmsNewThree = BigDecimal.ZERO;
        BigDecimal costYSmsNewFour = BigDecimal.ZERO;
        BigDecimal costYSmsNewFive = BigDecimal.ZERO;
        BigDecimal costYJntNewOne = BigDecimal.ZERO;
        BigDecimal costYJntNewTwo = BigDecimal.ZERO;
        BigDecimal costYJntNewThree = BigDecimal.ZERO;
        BigDecimal costYJntNewFour = BigDecimal.ZERO;
        BigDecimal costYJntNewFive = BigDecimal.ZERO;
        // Vip
        BigDecimal vipSmsNewOne = BigDecimal.ZERO;
        BigDecimal vipSmsNewTwo = BigDecimal.ZERO;
        BigDecimal vipSmsNewThree = BigDecimal.ZERO;
        BigDecimal vipSmsNewFour = BigDecimal.ZERO;
        BigDecimal vipSmsNewFive = BigDecimal.ZERO;
        BigDecimal vipJntNewOne = BigDecimal.ZERO;
        BigDecimal vipJntNewTwo = BigDecimal.ZERO;
        BigDecimal vipJntNewThree = BigDecimal.ZERO;
        BigDecimal vipJntNewFour = BigDecimal.ZERO;
        BigDecimal vipJntNewFive = BigDecimal.ZERO;
        // Expense   discount
        BigDecimal discountSmsNewOne = BigDecimal.ZERO;
        BigDecimal discountSmsNewTwo = BigDecimal.ZERO;
        BigDecimal discountSmsNewThree = BigDecimal.ZERO;
        BigDecimal discountSmsNewFour = BigDecimal.ZERO;
        BigDecimal discountSmsNewFive = BigDecimal.ZERO;
        BigDecimal discountJntNewOne = BigDecimal.ZERO;
        BigDecimal discountJntNewTwo = BigDecimal.ZERO;
        BigDecimal discountJntNewThree = BigDecimal.ZERO;
        BigDecimal discountJntNewFour = BigDecimal.ZERO;
        BigDecimal discountJntNewFive = BigDecimal.ZERO;
        // ODC
        BigDecimal odcSmsNewOne = BigDecimal.ZERO;
        BigDecimal odcSmsNewTwo = BigDecimal.ZERO;
        BigDecimal odcSmsNewThree = BigDecimal.ZERO;
        BigDecimal odcSmsNewFour = BigDecimal.ZERO;
        BigDecimal odcSmsNewFive = BigDecimal.ZERO;
        BigDecimal odcJntNewOne = BigDecimal.ZERO;
        BigDecimal odcJntNewTwo = BigDecimal.ZERO;
        BigDecimal odcJntNewThree = BigDecimal.ZERO;
        BigDecimal odcJntNewFour = BigDecimal.ZERO;
        BigDecimal odcJntNewFive = BigDecimal.ZERO;
        // Freight
        BigDecimal freightSmsNewOne = BigDecimal.ZERO;
        BigDecimal freightSmsNewTwo = BigDecimal.ZERO;
        BigDecimal freightSmsNewThree = BigDecimal.ZERO;
        BigDecimal freightSmsNewFour = BigDecimal.ZERO;
        BigDecimal freightSmsNewFive = BigDecimal.ZERO;
        BigDecimal freightJntNewOne = BigDecimal.ZERO;
        BigDecimal freightJntNewTwo = BigDecimal.ZERO;
        BigDecimal freightJntNewThree = BigDecimal.ZERO;
        BigDecimal freightJntNewFour = BigDecimal.ZERO;
        BigDecimal freightJntNewFive = BigDecimal.ZERO;
        for (InvestmentProduct investmentProduct : newProductList) {
            Map<String, Object> productMap = this.calculateProduct(investmentProduct);
            productMap.put("channelName", commonMap.containsKey(investmentProduct.getChannel()) ?
                    commonMap.get(investmentProduct.getChannel()).get("name") : "");
            productMap.put("categoryName", commonMap.containsKey(investmentProduct.getCategory()) ?
                    commonMap.get(investmentProduct.getCategory()).get("name") : "");
            productMap.put("brandName", commonMap.containsKey(investmentProduct.getBrand()) ?
                    commonMap.get(investmentProduct.getBrand()).get("name") : "");
            newProductMarginList.add(productMap);

            // total
            if (StringUtils.equals(brandMap.get(investmentProduct.getBrand()), "史密斯")) {
                invoicedSalesSmsNewOne = invoicedSalesSmsNewOne.add((BigDecimal) productMap.get("invoicedSalesOne"));
                invoicedSalesSmsNewTwo = invoicedSalesSmsNewTwo.add((BigDecimal) productMap.get("invoicedSalesTwo"));
                invoicedSalesSmsNewThree = invoicedSalesSmsNewThree.add((BigDecimal) productMap.get("invoicedSalesThree"));
                invoicedSalesSmsNewFour = invoicedSalesSmsNewFour.add((BigDecimal) productMap.get("invoicedSalesFour"));
                invoicedSalesSmsNewFive = invoicedSalesSmsNewFive.add((BigDecimal) productMap.get("invoicedSalesFive"));

                volumeSmsNewOne = volumeSmsNewOne.add((BigDecimal) productMap.get("volumeOne"));
                volumeSmsNewTwo = volumeSmsNewTwo.add((BigDecimal) productMap.get("volumeTwo"));
                volumeSmsNewThree = volumeSmsNewThree.add((BigDecimal) productMap.get("volumeThree"));
                volumeSmsNewFour = volumeSmsNewFour.add((BigDecimal) productMap.get("volumeFour"));
                volumeSmsNewFive = volumeSmsNewFive.add((BigDecimal) productMap.get("volumeFive"));

                costYSmsNewOne = costYSmsNewOne.add((BigDecimal) productMap.get("costYOne"));
                costYSmsNewTwo = costYSmsNewTwo.add((BigDecimal) productMap.get("costYTwo"));
                costYSmsNewThree = costYSmsNewThree.add((BigDecimal) productMap.get("costYThree"));
                costYSmsNewFour = costYSmsNewFour.add((BigDecimal) productMap.get("costYFour"));
                costYSmsNewFive = costYSmsNewFive.add((BigDecimal) productMap.get("costYFive"));

                vipSmsNewOne = vipSmsNewOne.add((BigDecimal) productMap.get("vipOne"));
                vipSmsNewTwo = vipSmsNewTwo.add((BigDecimal) productMap.get("vipTwo"));
                vipSmsNewThree = vipSmsNewThree.add((BigDecimal) productMap.get("vipThree"));
                vipSmsNewFour = vipSmsNewFour.add((BigDecimal) productMap.get("vipFour"));
                vipSmsNewFive = vipSmsNewFive.add((BigDecimal) productMap.get("vipFive"));

                discountSmsNewOne = discountSmsNewOne.add((BigDecimal) productMap.get("discountOne"));
                discountSmsNewTwo = discountSmsNewTwo.add((BigDecimal) productMap.get("discountTwo"));
                discountSmsNewThree = discountSmsNewThree.add((BigDecimal) productMap.get("discountThree"));
                discountSmsNewFour = discountSmsNewFour.add((BigDecimal) productMap.get("discountFour"));
                discountSmsNewFive = discountSmsNewFive.add((BigDecimal) productMap.get("discountFive"));

                odcSmsNewOne = odcSmsNewOne.add((BigDecimal) productMap.get("odcOne"));
                odcSmsNewTwo = odcSmsNewTwo.add((BigDecimal) productMap.get("odcTwo"));
                odcSmsNewThree = odcSmsNewThree.add((BigDecimal) productMap.get("odcThree"));
                odcSmsNewFour = odcSmsNewFour.add((BigDecimal) productMap.get("odcFour"));
                odcSmsNewFive = odcSmsNewFive.add((BigDecimal) productMap.get("odcFive"));

                freightSmsNewOne = freightSmsNewOne.add((BigDecimal) productMap.get("freightOne"));
                freightSmsNewTwo = freightSmsNewTwo.add((BigDecimal) productMap.get("freightTwo"));
                freightSmsNewThree = freightSmsNewThree.add((BigDecimal) productMap.get("freightThree"));
                freightSmsNewFour = freightSmsNewFour.add((BigDecimal) productMap.get("freightFour"));
                freightSmsNewFive = freightSmsNewFive.add((BigDecimal) productMap.get("freightFive"));

            } else if (StringUtils.equals(brandMap.get(investmentProduct.getBrand()), "佳尼特")) {
                invoicedSalesJntNewOne = invoicedSalesJntNewOne.add((BigDecimal) productMap.get("invoicedSalesOne"));
                invoicedSalesJntNewTwo = invoicedSalesJntNewTwo.add((BigDecimal) productMap.get("invoicedSalesTwo"));
                invoicedSalesJntNewThree = invoicedSalesJntNewThree.add((BigDecimal) productMap.get("invoicedSalesThree"));
                invoicedSalesJntNewFour = invoicedSalesJntNewFour.add((BigDecimal) productMap.get("invoicedSalesFour"));
                invoicedSalesJntNewFive = invoicedSalesJntNewFive.add((BigDecimal) productMap.get("invoicedSalesFive"));

                volumeJntNewOne = volumeJntNewOne.add((BigDecimal) productMap.get("volumeOne"));
                volumeJntNewTwo = volumeJntNewTwo.add((BigDecimal) productMap.get("volumeTwo"));
                volumeJntNewThree = volumeJntNewThree.add((BigDecimal) productMap.get("volumeThree"));
                volumeJntNewFour = volumeJntNewFour.add((BigDecimal) productMap.get("volumeFour"));
                volumeJntNewFive = volumeJntNewFive.add((BigDecimal) productMap.get("volumeFive"));

                costYJntNewOne = costYJntNewOne.add((BigDecimal) productMap.get("costYOne"));
                costYJntNewTwo = costYJntNewTwo.add((BigDecimal) productMap.get("costYTwo"));
                costYJntNewThree = costYJntNewThree.add((BigDecimal) productMap.get("costYThree"));
                costYJntNewFour = costYJntNewFour.add((BigDecimal) productMap.get("costYFour"));
                costYJntNewFive = costYJntNewFive.add((BigDecimal) productMap.get("costYFive"));

                vipJntNewOne = vipJntNewOne.add((BigDecimal) productMap.get("vipOne"));
                vipJntNewTwo = vipJntNewTwo.add((BigDecimal) productMap.get("vipTwo"));
                vipJntNewThree = vipJntNewThree.add((BigDecimal) productMap.get("vipThree"));
                vipJntNewFour = vipJntNewFour.add((BigDecimal) productMap.get("vipFour"));
                vipJntNewFive = vipJntNewFive.add((BigDecimal) productMap.get("vipFive"));

                discountJntNewOne = discountJntNewOne.add((BigDecimal) productMap.get("discountOne"));
                discountJntNewTwo = discountJntNewTwo.add((BigDecimal) productMap.get("discountTwo"));
                discountJntNewThree = discountJntNewThree.add((BigDecimal) productMap.get("discountThree"));
                discountJntNewFour = discountJntNewFour.add((BigDecimal) productMap.get("discountFour"));
                discountJntNewFive = discountJntNewFive.add((BigDecimal) productMap.get("discountFive"));

                odcJntNewOne = odcJntNewOne.add((BigDecimal) productMap.get("odcOne"));
                odcJntNewTwo = odcJntNewTwo.add((BigDecimal) productMap.get("odcTwo"));
                odcJntNewThree = odcJntNewThree.add((BigDecimal) productMap.get("odcThree"));
                odcJntNewFour = odcJntNewFour.add((BigDecimal) productMap.get("odcFour"));
                odcJntNewFive = odcJntNewFive.add((BigDecimal) productMap.get("odcFive"));

                freightJntNewOne = freightJntNewOne.add((BigDecimal) productMap.get("freightOne"));
                freightJntNewTwo = freightJntNewTwo.add((BigDecimal) productMap.get("freightTwo"));
                freightJntNewThree = freightJntNewThree.add((BigDecimal) productMap.get("freightThree"));
                freightJntNewFour = freightJntNewFour.add((BigDecimal) productMap.get("freightFour"));
                freightJntNewFive = freightJntNewFive.add((BigDecimal) productMap.get("freightFive"));
            }
        }
        marginMap.put("newProductMarginList", newProductMarginList);
        List<InvestmentProduct> replaceProductList = calculateDataDto.getReplaceProductData();
        List<Map<String, Object>> replaceProductMarginList = new ArrayList<>(replaceProductList.size());
        // invoicedSales
        BigDecimal invoicedSalesSmsReplaceOne = BigDecimal.ZERO;
        BigDecimal invoicedSalesSmsReplaceTwo = BigDecimal.ZERO;
        BigDecimal invoicedSalesSmsReplaceThree = BigDecimal.ZERO;
        BigDecimal invoicedSalesSmsReplaceFour = BigDecimal.ZERO;
        BigDecimal invoicedSalesSmsReplaceFive = BigDecimal.ZERO;
        BigDecimal invoicedSalesJntReplaceOne = BigDecimal.ZERO;
        BigDecimal invoicedSalesJntReplaceTwo = BigDecimal.ZERO;
        BigDecimal invoicedSalesJntReplaceThree = BigDecimal.ZERO;
        BigDecimal invoicedSalesJntReplaceFour = BigDecimal.ZERO;
        BigDecimal invoicedSalesJntReplaceFive = BigDecimal.ZERO;
        // Volume
        BigDecimal volumeSmsReplaceOne = BigDecimal.ZERO;
        BigDecimal volumeSmsReplaceTwo = BigDecimal.ZERO;
        BigDecimal volumeSmsReplaceThree = BigDecimal.ZERO;
        BigDecimal volumeSmsReplaceFour = BigDecimal.ZERO;
        BigDecimal volumeSmsReplaceFive = BigDecimal.ZERO;
        BigDecimal volumeJntReplaceOne = BigDecimal.ZERO;
        BigDecimal volumeJntReplaceTwo = BigDecimal.ZERO;
        BigDecimal volumeJntReplaceThree = BigDecimal.ZERO;
        BigDecimal volumeJntReplaceFour = BigDecimal.ZERO;
        BigDecimal volumeJntReplaceFive = BigDecimal.ZERO;
        // Cost
        BigDecimal costYSmsReplaceOne = BigDecimal.ZERO;
        BigDecimal costYSmsReplaceTwo = BigDecimal.ZERO;
        BigDecimal costYSmsReplaceThree = BigDecimal.ZERO;
        BigDecimal costYSmsReplaceFour = BigDecimal.ZERO;
        BigDecimal costYSmsReplaceFive = BigDecimal.ZERO;
        BigDecimal costYJntReplaceOne = BigDecimal.ZERO;
        BigDecimal costYJntReplaceTwo = BigDecimal.ZERO;
        BigDecimal costYJntReplaceThree = BigDecimal.ZERO;
        BigDecimal costYJntReplaceFour = BigDecimal.ZERO;
        BigDecimal costYJntReplaceFive = BigDecimal.ZERO;
        // Vip
        BigDecimal vipSmsReplaceOne = BigDecimal.ZERO;
        BigDecimal vipSmsReplaceTwo = BigDecimal.ZERO;
        BigDecimal vipSmsReplaceThree = BigDecimal.ZERO;
        BigDecimal vipSmsReplaceFour = BigDecimal.ZERO;
        BigDecimal vipSmsReplaceFive = BigDecimal.ZERO;
        BigDecimal vipJntReplaceOne = BigDecimal.ZERO;
        BigDecimal vipJntReplaceTwo = BigDecimal.ZERO;
        BigDecimal vipJntReplaceThree = BigDecimal.ZERO;
        BigDecimal vipJntReplaceFour = BigDecimal.ZERO;
        BigDecimal vipJntReplaceFive = BigDecimal.ZERO;
        // Expense   discount
        BigDecimal discountSmsReplaceOne = BigDecimal.ZERO;
        BigDecimal discountSmsReplaceTwo = BigDecimal.ZERO;
        BigDecimal discountSmsReplaceThree = BigDecimal.ZERO;
        BigDecimal discountSmsReplaceFour = BigDecimal.ZERO;
        BigDecimal discountSmsReplaceFive = BigDecimal.ZERO;
        BigDecimal discountJntReplaceOne = BigDecimal.ZERO;
        BigDecimal discountJntReplaceTwo = BigDecimal.ZERO;
        BigDecimal discountJntReplaceThree = BigDecimal.ZERO;
        BigDecimal discountJntReplaceFour = BigDecimal.ZERO;
        BigDecimal discountJntReplaceFive = BigDecimal.ZERO;
        // ODC
        BigDecimal odcSmsReplaceOne = BigDecimal.ZERO;
        BigDecimal odcSmsReplaceTwo = BigDecimal.ZERO;
        BigDecimal odcSmsReplaceThree = BigDecimal.ZERO;
        BigDecimal odcSmsReplaceFour = BigDecimal.ZERO;
        BigDecimal odcSmsReplaceFive = BigDecimal.ZERO;
        BigDecimal odcJntReplaceOne = BigDecimal.ZERO;
        BigDecimal odcJntReplaceTwo = BigDecimal.ZERO;
        BigDecimal odcJntReplaceThree = BigDecimal.ZERO;
        BigDecimal odcJntReplaceFour = BigDecimal.ZERO;
        BigDecimal odcJntReplaceFive = BigDecimal.ZERO;
        // Freight
        BigDecimal freightSmsReplaceOne = BigDecimal.ZERO;
        BigDecimal freightSmsReplaceTwo = BigDecimal.ZERO;
        BigDecimal freightSmsReplaceThree = BigDecimal.ZERO;
        BigDecimal freightSmsReplaceFour = BigDecimal.ZERO;
        BigDecimal freightSmsReplaceFive = BigDecimal.ZERO;
        BigDecimal freightJntReplaceOne = BigDecimal.ZERO;
        BigDecimal freightJntReplaceTwo = BigDecimal.ZERO;
        BigDecimal freightJntReplaceThree = BigDecimal.ZERO;
        BigDecimal freightJntReplaceFour = BigDecimal.ZERO;
        BigDecimal freightJntReplaceFive = BigDecimal.ZERO;
        for (InvestmentProduct investmentProduct : replaceProductList) {
            Map<String, Object> productMap = this.calculateProduct(investmentProduct);
            productMap.put("channelName", commonMap.containsKey(investmentProduct.getChannel()) ?
                    commonMap.get(investmentProduct.getChannel()).get("name") : "");
            productMap.put("categoryName", commonMap.containsKey(investmentProduct.getCategory()) ?
                    commonMap.get(investmentProduct.getCategory()).get("name") : "");
            productMap.put("brandName", commonMap.containsKey(investmentProduct.getBrand()) ?
                    commonMap.get(investmentProduct.getBrand()).get("name") : "");
            replaceProductMarginList.add(productMap);
            // total
            if (StringUtils.equals(brandMap.get(investmentProduct.getBrand()), "史密斯")) {
                invoicedSalesSmsReplaceOne = invoicedSalesSmsReplaceOne.add((BigDecimal) productMap.get("invoicedSalesOne"));
                invoicedSalesSmsReplaceTwo = invoicedSalesSmsReplaceTwo.add((BigDecimal) productMap.get("invoicedSalesTwo"));
                invoicedSalesSmsReplaceThree = invoicedSalesSmsReplaceThree.add((BigDecimal) productMap.get("invoicedSalesThree"));
                invoicedSalesSmsReplaceFour = invoicedSalesSmsReplaceFour.add((BigDecimal) productMap.get("invoicedSalesFour"));
                invoicedSalesSmsReplaceFive = invoicedSalesSmsReplaceFive.add((BigDecimal) productMap.get("invoicedSalesFive"));

                volumeSmsReplaceOne = volumeSmsReplaceOne.add((BigDecimal) productMap.get("volumeOne"));
                volumeSmsReplaceTwo = volumeSmsReplaceTwo.add((BigDecimal) productMap.get("volumeTwo"));
                volumeSmsReplaceThree = volumeSmsReplaceThree.add((BigDecimal) productMap.get("volumeThree"));
                volumeSmsReplaceFour = volumeSmsReplaceFour.add((BigDecimal) productMap.get("volumeFour"));
                volumeSmsReplaceFive = volumeSmsReplaceFive.add((BigDecimal) productMap.get("volumeFive"));

                costYSmsReplaceOne = costYSmsReplaceOne.add((BigDecimal) productMap.get("costYOne"));
                costYSmsReplaceTwo = costYSmsReplaceTwo.add((BigDecimal) productMap.get("costYTwo"));
                costYSmsReplaceThree = costYSmsReplaceThree.add((BigDecimal) productMap.get("costYThree"));
                costYSmsReplaceFour = costYSmsReplaceFour.add((BigDecimal) productMap.get("costYFour"));
                costYSmsReplaceFive = costYSmsReplaceFive.add((BigDecimal) productMap.get("costYFive"));

                vipSmsReplaceOne = vipSmsReplaceOne.add((BigDecimal) productMap.get("vipOne"));
                vipSmsReplaceTwo = vipSmsReplaceTwo.add((BigDecimal) productMap.get("vipTwo"));
                vipSmsReplaceThree = vipSmsReplaceThree.add((BigDecimal) productMap.get("vipThree"));
                vipSmsReplaceFour = vipSmsReplaceFour.add((BigDecimal) productMap.get("vipFour"));
                vipSmsReplaceFive = vipSmsReplaceFive.add((BigDecimal) productMap.get("vipFive"));

                discountSmsReplaceOne = discountSmsReplaceOne.add((BigDecimal) productMap.get("discountOne"));
                discountSmsReplaceTwo = discountSmsReplaceTwo.add((BigDecimal) productMap.get("discountTwo"));
                discountSmsReplaceThree = discountSmsReplaceThree.add((BigDecimal) productMap.get("discountThree"));
                discountSmsReplaceFour = discountSmsReplaceFour.add((BigDecimal) productMap.get("discountFour"));
                discountSmsReplaceFive = discountSmsReplaceFive.add((BigDecimal) productMap.get("discountFive"));

                odcSmsReplaceOne = odcSmsReplaceOne.add((BigDecimal) productMap.get("odcOne"));
                odcSmsReplaceTwo = odcSmsReplaceTwo.add((BigDecimal) productMap.get("odcTwo"));
                odcSmsReplaceThree = odcSmsReplaceThree.add((BigDecimal) productMap.get("odcThree"));
                odcSmsReplaceFour = odcSmsReplaceFour.add((BigDecimal) productMap.get("odcFour"));
                odcSmsReplaceFive = odcSmsReplaceFive.add((BigDecimal) productMap.get("odcFive"));

                freightSmsReplaceOne = freightSmsReplaceOne.add((BigDecimal) productMap.get("freightOne"));
                freightSmsReplaceTwo = freightSmsReplaceTwo.add((BigDecimal) productMap.get("freightTwo"));
                freightSmsReplaceThree = freightSmsReplaceThree.add((BigDecimal) productMap.get("freightThree"));
                freightSmsReplaceFour = freightSmsReplaceFour.add((BigDecimal) productMap.get("freightFour"));
                freightSmsReplaceFive = freightSmsReplaceFive.add((BigDecimal) productMap.get("freightFive"));

            } else if (StringUtils.equals(brandMap.get(investmentProduct.getBrand()), "佳尼特")) {
                invoicedSalesJntReplaceOne = invoicedSalesJntReplaceOne.add((BigDecimal) productMap.get("invoicedSalesOne"));
                invoicedSalesJntReplaceTwo = invoicedSalesJntReplaceTwo.add((BigDecimal) productMap.get("invoicedSalesTwo"));
                invoicedSalesJntReplaceThree = invoicedSalesJntReplaceThree.add((BigDecimal) productMap.get("invoicedSalesThree"));
                invoicedSalesJntReplaceFour = invoicedSalesJntReplaceFour.add((BigDecimal) productMap.get("invoicedSalesFour"));
                invoicedSalesJntReplaceFive = invoicedSalesJntReplaceFive.add((BigDecimal) productMap.get("invoicedSalesFive"));

                volumeJntReplaceOne = volumeJntReplaceOne.add((BigDecimal) productMap.get("volumeOne"));
                volumeJntReplaceTwo = volumeJntReplaceTwo.add((BigDecimal) productMap.get("volumeTwo"));
                volumeJntReplaceThree = volumeJntReplaceThree.add((BigDecimal) productMap.get("volumeThree"));
                volumeJntReplaceFour = volumeJntReplaceFour.add((BigDecimal) productMap.get("volumeFour"));
                volumeJntReplaceFive = volumeJntReplaceFive.add((BigDecimal) productMap.get("volumeFive"));

                costYJntReplaceOne = costYJntReplaceOne.add((BigDecimal) productMap.get("costYOne"));
                costYJntReplaceTwo = costYJntReplaceTwo.add((BigDecimal) productMap.get("costYTwo"));
                costYJntReplaceThree = costYJntReplaceThree.add((BigDecimal) productMap.get("costYThree"));
                costYJntReplaceFour = costYJntReplaceFour.add((BigDecimal) productMap.get("costYFour"));
                costYJntReplaceFive = costYJntReplaceFive.add((BigDecimal) productMap.get("costYFive"));

                vipJntReplaceOne = vipJntReplaceOne.add((BigDecimal) productMap.get("vipOne"));
                vipJntReplaceTwo = vipJntReplaceTwo.add((BigDecimal) productMap.get("vipTwo"));
                vipJntReplaceThree = vipJntReplaceThree.add((BigDecimal) productMap.get("vipThree"));
                vipJntReplaceFour = vipJntReplaceFour.add((BigDecimal) productMap.get("vipFour"));
                vipJntReplaceFive = vipJntReplaceFive.add((BigDecimal) productMap.get("vipFive"));

                discountJntReplaceOne = discountJntReplaceOne.add((BigDecimal) productMap.get("discountOne"));
                discountJntReplaceTwo = discountJntReplaceTwo.add((BigDecimal) productMap.get("discountTwo"));
                discountJntReplaceThree = discountJntReplaceThree.add((BigDecimal) productMap.get("discountThree"));
                discountJntReplaceFour = discountJntReplaceFour.add((BigDecimal) productMap.get("discountFour"));
                discountJntReplaceFive = discountJntReplaceFive.add((BigDecimal) productMap.get("discountFive"));

                odcJntReplaceOne = odcJntReplaceOne.add((BigDecimal) productMap.get("odcOne"));
                odcJntReplaceTwo = odcJntReplaceTwo.add((BigDecimal) productMap.get("odcTwo"));
                odcJntReplaceThree = odcJntReplaceThree.add((BigDecimal) productMap.get("odcThree"));
                odcJntReplaceFour = odcJntReplaceFour.add((BigDecimal) productMap.get("odcFour"));
                odcJntReplaceFive = odcJntReplaceFive.add((BigDecimal) productMap.get("odcFive"));

                freightJntReplaceOne = freightJntReplaceOne.add((BigDecimal) productMap.get("freightOne"));
                freightJntReplaceTwo = freightJntReplaceTwo.add((BigDecimal) productMap.get("freightTwo"));
                freightJntReplaceThree = freightJntReplaceThree.add((BigDecimal) productMap.get("freightThree"));
                freightJntReplaceFour = freightJntReplaceFour.add((BigDecimal) productMap.get("freightFour"));
                freightJntReplaceFive = freightJntReplaceFive.add((BigDecimal) productMap.get("freightFive"));
            }
        }
        marginMap.put("replaceProductMarginList", replaceProductMarginList);

        List<Map<String, Object>> incrementList = new ArrayList<>();
        Map<String, Object> smsIncrementData = new HashMap<>();
        smsIncrementData.put("brand", "史密斯");
        smsIncrementData.put("invoicedSalesOne", invoicedSalesSmsNewOne.subtract(invoicedSalesSmsReplaceOne));
        smsIncrementData.put("invoicedSalesTwo", invoicedSalesSmsNewTwo.subtract(invoicedSalesSmsReplaceTwo));
        smsIncrementData.put("invoicedSalesThree", invoicedSalesSmsNewThree.subtract(invoicedSalesSmsReplaceThree));
        smsIncrementData.put("invoicedSalesFour", invoicedSalesSmsNewFour.subtract(invoicedSalesSmsReplaceFour));
        smsIncrementData.put("invoicedSalesFive", invoicedSalesSmsNewFive.subtract(invoicedSalesSmsReplaceFive));

        smsIncrementData.put("volumeOne", volumeSmsNewOne.subtract(volumeSmsReplaceOne));
        smsIncrementData.put("volumeTwo", volumeSmsNewTwo.subtract(volumeSmsReplaceTwo));
        smsIncrementData.put("volumeThree", volumeSmsNewThree.subtract(volumeSmsReplaceThree));
        smsIncrementData.put("volumeFour", volumeSmsNewFour.subtract(volumeSmsReplaceFour));
        smsIncrementData.put("volumeFive", volumeSmsNewFive.subtract(volumeSmsReplaceFive));

        smsIncrementData.put("costYOne", costYSmsNewOne.subtract(costYSmsReplaceOne));
        smsIncrementData.put("costYTwo", costYSmsNewTwo.subtract(costYSmsReplaceTwo));
        smsIncrementData.put("costYThree", costYSmsNewThree.subtract(costYSmsReplaceThree));
        smsIncrementData.put("costYFour", costYSmsNewFour.subtract(costYSmsReplaceFour));
        smsIncrementData.put("costYFive", costYSmsNewFive.subtract(costYSmsReplaceFive));

        smsIncrementData.put("vipOne", vipSmsNewOne.subtract(vipSmsReplaceOne));
        smsIncrementData.put("vipTwo", vipSmsNewTwo.subtract(vipSmsReplaceTwo));
        smsIncrementData.put("vipThree", vipSmsNewThree.subtract(vipSmsReplaceThree));
        smsIncrementData.put("vipFour", vipSmsNewFour.subtract(vipSmsReplaceFour));
        smsIncrementData.put("vipFive", vipSmsNewFive.subtract(vipSmsReplaceFive));

        smsIncrementData.put("discountOne", discountSmsNewOne.subtract(discountSmsReplaceOne));
        smsIncrementData.put("discountTwo", discountSmsNewTwo.subtract(discountSmsReplaceTwo));
        smsIncrementData.put("discountThree", discountSmsNewThree.subtract(discountSmsReplaceThree));
        smsIncrementData.put("discountFour", discountSmsNewFour.subtract(discountSmsReplaceFour));
        smsIncrementData.put("discountFive", discountSmsNewFive.subtract(discountSmsReplaceFive));

        smsIncrementData.put("odcOne", odcSmsNewOne.subtract(odcSmsReplaceOne));
        smsIncrementData.put("odcTwo", odcSmsNewTwo.subtract(odcSmsReplaceTwo));
        smsIncrementData.put("odcThree", odcSmsNewThree.subtract(odcSmsReplaceThree));
        smsIncrementData.put("odcFour", odcSmsNewFour.subtract(odcSmsReplaceFour));
        smsIncrementData.put("odcFive", odcSmsNewFive.subtract(odcSmsReplaceFive));

        smsIncrementData.put("freightOne", freightSmsNewOne.subtract(freightSmsReplaceOne));
        smsIncrementData.put("freightTwo", freightSmsNewTwo.subtract(freightSmsReplaceTwo));
        smsIncrementData.put("freightThree", freightSmsNewThree.subtract(freightSmsReplaceThree));
        smsIncrementData.put("freightFour", freightSmsNewFour.subtract(freightSmsReplaceFour));
        smsIncrementData.put("freightFive", freightSmsNewFive.subtract(freightSmsReplaceFive));

        incrementList.add(smsIncrementData);
        Map<String, Object> jntIncrementData = new HashMap<>();
        jntIncrementData.put("brand", "佳尼特");
        jntIncrementData.put("invoicedSalesOne", invoicedSalesJntNewOne.subtract(invoicedSalesJntReplaceOne));
        jntIncrementData.put("invoicedSalesTwo", invoicedSalesJntNewTwo.subtract(invoicedSalesJntReplaceTwo));
        jntIncrementData.put("invoicedSalesThree", invoicedSalesJntNewThree.subtract(invoicedSalesJntReplaceThree));
        jntIncrementData.put("invoicedSalesFour", invoicedSalesJntNewFour.subtract(invoicedSalesJntReplaceFour));
        jntIncrementData.put("invoicedSalesFive", invoicedSalesJntNewFive.subtract(invoicedSalesJntReplaceFive));

        jntIncrementData.put("volumeOne", volumeJntNewOne.subtract(volumeJntReplaceOne));
        jntIncrementData.put("volumeTwo", volumeJntNewTwo.subtract(volumeJntReplaceTwo));
        jntIncrementData.put("volumeThree", volumeJntNewThree.subtract(volumeJntReplaceThree));
        jntIncrementData.put("volumeFour", volumeJntNewFour.subtract(volumeJntReplaceFour));
        jntIncrementData.put("volumeFive", volumeJntNewFive.subtract(volumeJntReplaceFive));

        jntIncrementData.put("costYOne", costYJntNewOne.subtract(costYJntReplaceOne));
        jntIncrementData.put("costYTwo", costYJntNewTwo.subtract(costYJntReplaceTwo));
        jntIncrementData.put("costYThree", costYJntNewThree.subtract(costYJntReplaceThree));
        jntIncrementData.put("costYFour", costYJntNewFour.subtract(costYJntReplaceFour));
        jntIncrementData.put("costYFive", costYJntNewFive.subtract(costYJntReplaceFive));

        jntIncrementData.put("vipOne", vipJntNewOne.subtract(vipJntReplaceOne));
        jntIncrementData.put("vipTwo", vipJntNewTwo.subtract(vipJntReplaceTwo));
        jntIncrementData.put("vipThree", vipJntNewThree.subtract(vipJntReplaceThree));
        jntIncrementData.put("vipFour", vipJntNewFour.subtract(vipJntReplaceFour));
        jntIncrementData.put("vipFive", vipJntNewFive.subtract(vipJntReplaceFive));

        jntIncrementData.put("discountOne", discountJntNewOne.subtract(discountJntReplaceOne));
        jntIncrementData.put("discountTwo", discountJntNewTwo.subtract(discountJntReplaceTwo));
        jntIncrementData.put("discountThree", discountJntNewThree.subtract(discountJntReplaceThree));
        jntIncrementData.put("discountFour", discountJntNewFour.subtract(discountJntReplaceFour));
        jntIncrementData.put("discountFive", discountJntNewFive.subtract(discountJntReplaceFive));

        jntIncrementData.put("odcOne", odcJntNewOne.subtract(odcJntReplaceOne));
        jntIncrementData.put("odcTwo", odcJntNewTwo.subtract(odcJntReplaceTwo));
        jntIncrementData.put("odcThree", odcJntNewThree.subtract(odcJntReplaceThree));
        jntIncrementData.put("odcFour", odcJntNewFour.subtract(odcJntReplaceFour));
        jntIncrementData.put("odcFive", odcJntNewFive.subtract(odcJntReplaceFive));

        jntIncrementData.put("freightOne", freightJntNewOne.subtract(freightJntReplaceOne));
        jntIncrementData.put("freightTwo", freightJntNewTwo.subtract(freightJntReplaceTwo));
        jntIncrementData.put("freightThree", freightJntNewThree.subtract(freightJntReplaceThree));
        jntIncrementData.put("freightFour", freightJntNewFour.subtract(freightJntReplaceFour));
        jntIncrementData.put("freightFive", freightJntNewFive.subtract(freightJntReplaceFive));
        incrementList.add(jntIncrementData);
        marginMap.put("increaseMarginList", incrementList);
        dataMap.put("marginMap", marginMap);

        // Depreciation
        List<InvestmentInput> investmentInputList = calculateDataDto.getInvestData();
        Map<String, Object> depreciationMap = calculateDepreciation(investmentInputList);
        dataMap.put("depreciationMap", depreciationMap);

        // Profit Statement
        Map<String, Object> profitMap = calculateProfit();
        List<Map<String, Object>> profitList = new ArrayList<>();
        //Units
        Map<String, Object> unitMap = new HashMap<>();
        unitMap.put("sort", 1);
        unitMap.put("typeName", "Units");
        BigDecimal unitsSmsYOne = calculateUnits(volumeSmsNewOne, volumeSmsReplaceOne);
        unitMap.put("smsYOne", unitsSmsYOne);
        BigDecimal unitsSmsYTwo = calculateUnits(volumeSmsNewTwo, volumeSmsReplaceTwo);
        unitMap.put("smsYTwo", unitsSmsYTwo);
        BigDecimal unitsSmsYThree = calculateUnits(volumeSmsNewThree, volumeSmsReplaceThree);
        unitMap.put("smsYThree", unitsSmsYThree);
        BigDecimal unitsSmsYFour = calculateUnits(volumeSmsNewFour, volumeSmsReplaceFour);
        unitMap.put("smsYFour", unitsSmsYFour);
        BigDecimal unitsSmsYFive = calculateUnits(volumeSmsNewFive, volumeSmsReplaceFive);
        unitMap.put("smsYFive", unitsSmsYFive);
        BigDecimal unitsJntYOne = calculateUnits(volumeJntNewOne, volumeJntReplaceOne);
        unitMap.put("jntYOne", unitsJntYOne);
        BigDecimal unitsJntYTwo = calculateUnits(volumeJntNewTwo, volumeJntReplaceTwo);
        unitMap.put("jntYTwo", unitsJntYTwo);
        BigDecimal unitsJntYThree = calculateUnits(volumeJntNewThree, volumeJntReplaceThree);
        unitMap.put("jntYThree", unitsJntYThree);
        BigDecimal unitsJntYFour = calculateUnits(volumeJntNewFour, volumeJntReplaceFour);
        unitMap.put("jntYFour", unitsJntYFour);
        BigDecimal unitsJntYFive = calculateUnits(volumeJntNewFive, volumeJntReplaceFive);
        unitMap.put("jntYFive", unitsJntYFive);
        unitMap.put("blankYOne", BigDecimal.ZERO);
        unitMap.put("blankYTwo", BigDecimal.ZERO);
        unitMap.put("blankYThree", BigDecimal.ZERO);
        unitMap.put("blankYFour", BigDecimal.ZERO);
        unitMap.put("blankYFive", BigDecimal.ZERO);

        BigDecimal unitsYOne;
        BigDecimal unitsYTwo;
        BigDecimal unitsYThree;
        BigDecimal unitsYFour;
        BigDecimal unitsYFive;
        unitsYOne = unitsSmsYOne.add(unitsJntYOne);
        unitsYTwo = unitsSmsYTwo.add(unitsJntYTwo);
        unitsYThree = unitsSmsYThree.add(unitsJntYThree);
        unitsYFour = unitsSmsYFour.add(unitsJntYFour);
        unitsYFive = unitsSmsYFive.add(unitsJntYFive);

//        unitMap.put("yZero", unitsYOne);
        unitMap.put("yOne", unitsYOne);
        unitMap.put("yTwo", unitsYTwo);
        unitMap.put("yThree", unitsYThree);
        unitMap.put("yFour", unitsYFour);
        unitMap.put("yFive", unitsYFive);
        profitList.add(unitMap);
        // Net Invoiced Sales (NIS)
        Map<String, Object> nisMap = new HashMap<>();
        nisMap.put("sort", 3);
        nisMap.put("typeName", "Net Invoiced Sales (NIS)");
        BigDecimal nisSmsYOne = calculateNIS(invoicedSalesSmsNewOne, invoicedSalesSmsReplaceOne);
        nisMap.put("smsYOne", nisSmsYOne);
        BigDecimal nisSmsYTwo = calculateNIS(invoicedSalesSmsNewTwo, invoicedSalesSmsReplaceTwo);
        nisMap.put("smsYTwo", nisSmsYTwo);
        BigDecimal nisSmsYThree = calculateNIS(invoicedSalesSmsNewThree, invoicedSalesSmsReplaceThree);
        nisMap.put("smsYThree", nisSmsYThree);
        BigDecimal nisSmsYFour = calculateNIS(invoicedSalesSmsNewFour, invoicedSalesSmsReplaceFour);
        nisMap.put("smsYFour", nisSmsYFour);
        BigDecimal nisSmsYFive = calculateNIS(invoicedSalesSmsNewFive, invoicedSalesSmsReplaceFive);
        nisMap.put("smsYFive", nisSmsYFive);
        BigDecimal nisJntYOne = calculateNIS(invoicedSalesJntNewOne, invoicedSalesJntReplaceOne);
        nisMap.put("jntYOne", nisJntYOne);
        BigDecimal nisJntYTwo = calculateNIS(invoicedSalesJntNewTwo, invoicedSalesJntReplaceTwo);
        nisMap.put("jntYTwo", nisJntYTwo);
        BigDecimal nisJntYThree = calculateNIS(invoicedSalesJntNewThree, invoicedSalesJntReplaceThree);
        nisMap.put("jntYThree", nisJntYThree);
        BigDecimal nisJntYFour = calculateNIS(invoicedSalesJntNewFour, invoicedSalesJntReplaceFour);
        nisMap.put("jntYFour", nisJntYFour);
        BigDecimal nisJntYFive = calculateNIS(invoicedSalesJntNewFive, invoicedSalesJntReplaceFive);
        nisMap.put("jntYFive", nisJntYFive);
        nisMap.put("blankYOne", BigDecimal.ZERO);
        nisMap.put("blankYTwo", BigDecimal.ZERO);
        nisMap.put("blankYThree", BigDecimal.ZERO);
        nisMap.put("blankYFour", BigDecimal.ZERO);
        nisMap.put("blankYFive", BigDecimal.ZERO);

        // todo nis汇总数据
        BigDecimal nisYOne;
        BigDecimal nisYTwo;
        BigDecimal nisYThree;
        BigDecimal nisYFour;
        BigDecimal nisYFive;
        nisYOne = nisSmsYOne.add(nisJntYOne);
        nisYTwo = nisSmsYTwo.add(nisJntYTwo);
        nisYThree = nisSmsYThree.add(nisJntYThree);
        nisYFour = nisSmsYFour.add(nisJntYFour);
        nisYFive = nisSmsYFive.add(nisJntYFive);


        nisMap.put("yOne", nisYOne);
        nisMap.put("yTwo", nisYTwo);
        nisMap.put("yThree", nisYThree);
        nisMap.put("yFour", nisYFour);
        nisMap.put("yFive", nisYFive);

        // Selling Price per unit
        Map<String, Object> perUnitMap = new HashMap<>();
        perUnitMap.put("sort", 2);
        perUnitMap.put("typeName", "Selling Price per unit");
        BigDecimal perUnitsSmsYOne = calculatePerUnits(unitsSmsYOne, nisSmsYOne);
        perUnitMap.put("smsYOne", perUnitsSmsYOne);
        BigDecimal perUnitsSmsYTwo = calculatePerUnits(unitsSmsYTwo, nisSmsYTwo);
        perUnitMap.put("smsYTwo", perUnitsSmsYTwo);
        BigDecimal perUnitsSmsYThree = calculatePerUnits(unitsSmsYThree, nisSmsYThree);
        perUnitMap.put("smsYThree", perUnitsSmsYThree);
        BigDecimal perUnitsSmsYFour = calculatePerUnits(unitsSmsYFour, nisSmsYFour);
        perUnitMap.put("smsYFour", perUnitsSmsYFour);
        BigDecimal perUnitsSmsYFive = calculatePerUnits(unitsSmsYFive, nisSmsYFive);
        perUnitMap.put("smsYFive", perUnitsSmsYFive);
        BigDecimal perUnitsJntYOne = calculatePerUnits(unitsJntYOne, nisJntYOne);
        perUnitMap.put("jntYOne", perUnitsJntYOne);
        BigDecimal perUnitsJntYTwo = calculatePerUnits(unitsJntYTwo, nisJntYTwo);
        perUnitMap.put("jntYTwo", perUnitsJntYTwo);
        BigDecimal perUnitsJntYThree = calculatePerUnits(unitsJntYThree, nisJntYThree);
        perUnitMap.put("jntYThree", perUnitsJntYThree);
        BigDecimal perUnitsJntYFour = calculatePerUnits(unitsJntYFour, nisJntYFour);
        perUnitMap.put("jntYFour", perUnitsJntYFour);
        BigDecimal perUnitsJntYFive = calculatePerUnits(unitsJntYFive, nisJntYFive);
        perUnitMap.put("jntYFive", perUnitsJntYFive);
        perUnitMap.put("blankYOne", BigDecimal.ZERO);
        perUnitMap.put("blankYTwo", BigDecimal.ZERO);
        perUnitMap.put("blankYThree", BigDecimal.ZERO);
        perUnitMap.put("blankYFour", BigDecimal.ZERO);
        perUnitMap.put("blankYFive", BigDecimal.ZERO);

        perUnitMap.put("yOne", perUnitsSmsYOne.add(perUnitsJntYOne));
        perUnitMap.put("yTwo", perUnitsSmsYTwo.add(perUnitsJntYTwo));
        perUnitMap.put("yThree", perUnitsSmsYThree.add(perUnitsJntYThree));
        perUnitMap.put("yFour", perUnitsSmsYFour.add(perUnitsJntYFour));
        perUnitMap.put("yFive", perUnitsSmsYFive.add(perUnitsJntYFive));
        profitList.add(perUnitMap);

        profitList.add(nisMap);

        // Customer discounts and rebates (VIP)&Cash discount
        Map<String, Object> vipMap = new HashMap<>();
        vipMap.put("sort", 4);
        vipMap.put("typeName", "Customer discounts and rebates (VIP)&Cash discount");
        BigDecimal vipSmsYOne = calculateVip(vipSmsNewOne, vipSmsReplaceOne);
        vipMap.put("smsYOne", vipSmsYOne);
        BigDecimal vipSmsYTwo = calculateVip(vipSmsNewTwo, vipSmsReplaceTwo);
        vipMap.put("smsYTwo", vipSmsYTwo);
        BigDecimal vipSmsYThree = calculateVip(vipSmsNewThree, vipSmsReplaceThree);
        vipMap.put("smsYThree", vipSmsYThree);
        BigDecimal vipSmsYFour = calculateVip(vipSmsNewFour, vipSmsReplaceFour);
        vipMap.put("smsYFour", vipSmsYFour);
        BigDecimal vipSmsYFive = calculateVip(vipSmsNewFive, vipSmsReplaceFive);
        vipMap.put("smsYFive", vipSmsYFive);
        BigDecimal vipJntYOne = calculateVip(vipJntNewOne, vipJntReplaceOne);
        vipMap.put("jntYOne", vipJntYOne);
        BigDecimal vipJntYTwo = calculateVip(vipJntNewTwo, vipJntReplaceTwo);
        vipMap.put("jntYTwo", vipJntYTwo);
        BigDecimal vipJntYThree = calculateVip(vipJntNewThree, vipJntReplaceThree);
        vipMap.put("jntYThree", vipJntYThree);
        BigDecimal vipJntYFour = calculateVip(vipJntNewFour, vipJntReplaceFour);
        vipMap.put("jntYFour", vipJntYFour);
        BigDecimal vipJntYFive = calculateVip(vipJntNewFive, vipJntReplaceFive);
        vipMap.put("jntYFive", vipJntYFive);
        vipMap.put("blankYOne", BigDecimal.ZERO);
        vipMap.put("blankYTwo", BigDecimal.ZERO);
        vipMap.put("blankYThree", BigDecimal.ZERO);
        vipMap.put("blankYFour", BigDecimal.ZERO);
        vipMap.put("blankYFive", BigDecimal.ZERO);

        BigDecimal vipYOne;
        BigDecimal vipYTwo;
        BigDecimal vipYThree;
        BigDecimal vipYFour;
        BigDecimal vipYFive;
        vipYOne = vipSmsYOne.add(vipJntYOne);
        vipYTwo = vipSmsYTwo.add(vipJntYTwo);
        vipYThree = vipSmsYThree.add(vipJntYThree);
        vipYFour = vipSmsYFour.add(vipJntYFour);
        vipYFive = vipSmsYFive.add(vipJntYFive);

        vipMap.put("yZero", calculateRate(vipYOne, nisYOne));
        vipMap.put("yOne", vipYOne);
        vipMap.put("yTwo", vipYTwo);
        vipMap.put("yThree", vipYThree);
        vipMap.put("yFour", vipYFour);
        vipMap.put("yFive", vipYFive);
        profitList.add(vipMap);

        // Expense discount
        Map<String, Object> discountMap = new HashMap<>();
        discountMap.put("sort", 5);
        discountMap.put("typeName", "Expense discount");
        BigDecimal discountSmsYOne = calculateVip(discountSmsNewOne, discountSmsReplaceOne);
        discountMap.put("smsYOne", discountSmsYOne);
        BigDecimal discountSmsYTwo = calculateVip(discountSmsNewTwo, discountSmsReplaceTwo);
        discountMap.put("smsYTwo", discountSmsYTwo);
        BigDecimal discountSmsYThree = calculateVip(discountSmsNewThree, discountSmsReplaceThree);
        discountMap.put("smsYThree", discountSmsYThree);
        BigDecimal discountSmsYFour = calculateVip(discountSmsNewFour, discountSmsReplaceFour);
        discountMap.put("smsYFour", discountSmsYFour);
        BigDecimal discountSmsYFive = calculateVip(discountSmsNewFive, discountSmsReplaceFive);
        discountMap.put("smsYFive", discountSmsYFive);
        BigDecimal discountJntYOne = calculateVip(discountJntNewOne, discountJntReplaceOne);
        discountMap.put("jntYOne", discountJntYOne);
        BigDecimal discountJntYTwo = calculateVip(discountJntNewTwo, discountJntReplaceTwo);
        discountMap.put("jntYTwo", discountJntYTwo);
        BigDecimal discountJntYThree = calculateVip(discountJntNewThree, discountJntReplaceThree);
        discountMap.put("jntYThree", discountJntYThree);
        BigDecimal discountJntYFour = calculateVip(discountJntNewFour, discountJntReplaceFour);
        discountMap.put("jntYFour", discountJntYFour);
        BigDecimal discountJntYFive = calculateVip(discountJntNewFive, discountJntReplaceFive);
        discountMap.put("jntYFive", discountJntYFive);
        discountMap.put("blankYOne", BigDecimal.ZERO);
        discountMap.put("blankYTwo", BigDecimal.ZERO);
        discountMap.put("blankYThree", BigDecimal.ZERO);
        discountMap.put("blankYFour", BigDecimal.ZERO);
        discountMap.put("blankYFive", BigDecimal.ZERO);

        BigDecimal discountYOne;
        BigDecimal discountYTwo;
        BigDecimal discountYThree;
        BigDecimal discountYFour;
        BigDecimal discountYFive;
        discountYOne = discountSmsYOne.add(discountJntYOne);
        discountYTwo = discountSmsYTwo.add(discountJntYTwo);
        discountYThree = discountSmsYThree.add(discountJntYThree);
        discountYFour = discountSmsYFour.add(discountJntYFour);
        discountYFive = discountSmsYFive.add(discountJntYFive);

        discountMap.put("yZero", calculateRate(discountYOne, nisYOne));
        discountMap.put("yOne", discountYOne);
        discountMap.put("yTwo", discountYTwo);
        discountMap.put("yThree", discountYThree);
        discountMap.put("yFour", discountYFour);
        discountMap.put("yFive", discountYFive);
        profitList.add(discountMap);

        // Net sales
        Map<String, Object> netSalesMap = new HashMap<>();
        netSalesMap.put("sort", 6);
        netSalesMap.put("typeName", "Net sales");
        BigDecimal netSalesSmsYOne = calculateNetSales(nisSmsYOne, vipSmsYOne, discountSmsYOne);
        netSalesMap.put("smsYOne", netSalesSmsYOne);
        BigDecimal netSalesSmsYTwo = calculateNetSales(nisSmsYTwo, vipSmsYTwo, discountSmsYTwo);
        netSalesMap.put("smsYTwo", netSalesSmsYTwo);
        BigDecimal netSalesSmsYThree = calculateNetSales(nisSmsYThree, vipSmsYThree, discountSmsYThree);
        netSalesMap.put("smsYThree", netSalesSmsYThree);
        BigDecimal netSalesSmsYFour = calculateNetSales(nisSmsYFour, vipSmsYFour, discountSmsYFour);
        netSalesMap.put("smsYFour", netSalesSmsYFour);
        BigDecimal netSalesSmsYFive = calculateNetSales(nisSmsYFive, vipSmsYFive, discountSmsYFive);
        netSalesMap.put("smsYFive", netSalesSmsYFive);
        BigDecimal netSalesJntYOne = calculateNetSales(nisJntYOne, vipJntYOne, discountJntYOne);
        netSalesMap.put("jntYOne", netSalesJntYOne);
        BigDecimal netSalesJntYTwo = calculateNetSales(nisJntYTwo, vipJntYTwo, discountJntYTwo);
        netSalesMap.put("jntYTwo", netSalesJntYTwo);
        BigDecimal netSalesJntYThree = calculateNetSales(nisJntYThree, vipJntYThree, discountJntYThree);
        netSalesMap.put("jntYThree", netSalesJntYThree);
        BigDecimal netSalesJntYFour = calculateNetSales(nisJntYFour, vipJntYFour, discountJntYFour);
        netSalesMap.put("jntYFour", netSalesJntYFour);
        BigDecimal netSalesJntYFive = calculateNetSales(nisJntYFive, vipJntYFive, discountJntYFive);
        netSalesMap.put("jntYFive", netSalesJntYFive);

        netSalesMap.put("blankYOne", BigDecimal.ZERO);
        netSalesMap.put("blankYTwo", BigDecimal.ZERO);
        netSalesMap.put("blankYThree", BigDecimal.ZERO);
        netSalesMap.put("blankYFour", BigDecimal.ZERO);
        netSalesMap.put("blankYFive", BigDecimal.ZERO);

        // todo netSales汇总数据
        BigDecimal netSalesYOne;
        BigDecimal netSalesYTwo;
        BigDecimal netSalesYThree;
        BigDecimal netSalesYFour;
        BigDecimal netSalesYFive;
        netSalesYOne = netSalesSmsYOne.add(netSalesJntYOne);
        netSalesYTwo = netSalesSmsYTwo.add(netSalesJntYTwo);
        netSalesYThree = netSalesSmsYThree.add(netSalesJntYThree);
        netSalesYFour = netSalesSmsYFour.add(netSalesJntYFour);
        netSalesYFive = netSalesSmsYFive.add(netSalesJntYFive);

        netSalesMap.put("yOne", netSalesYOne);
        netSalesMap.put("yTwo", netSalesYTwo);
        netSalesMap.put("yThree", netSalesYThree);
        netSalesMap.put("yFour", netSalesYFour);
        netSalesMap.put("yFive", netSalesYFive);
        profitList.add(netSalesMap);

        // Total Product cost
        Map<String, Object> costMap = new HashMap<>();
        costMap.put("sort", 8);
        costMap.put("typeName", "Total Product cost");
        BigDecimal costSmsYOne = calculateVip(costYSmsNewOne, costYSmsReplaceOne);
        costMap.put("smsYOne", costSmsYOne);
        BigDecimal costSmsYTwo = calculateVip(costYSmsNewTwo, costYSmsReplaceTwo);
        costMap.put("smsYTwo", costSmsYTwo);
        BigDecimal costSmsYThree = calculateVip(costYSmsNewThree, costYSmsReplaceThree);
        costMap.put("smsYThree", costSmsYThree);
        BigDecimal costSmsYFour = calculateVip(costYSmsNewFour, costYSmsReplaceFour);
        costMap.put("smsYFour", costSmsYFour);
        BigDecimal costSmsYFive = calculateVip(costYSmsNewFive, costYSmsReplaceFive);
        costMap.put("smsYFive", costSmsYFive);
        BigDecimal costJntYOne = calculateVip(costYJntNewOne, costYJntReplaceOne);
        costMap.put("jntYOne", costJntYOne);
        BigDecimal costJntYTwo = calculateVip(costYJntNewTwo, costYJntReplaceTwo);
        costMap.put("jntYTwo", costJntYTwo);
        BigDecimal costJntYThree = calculateVip(costYJntNewThree, costYJntReplaceThree);
        costMap.put("jntYThree", costJntYThree);
        BigDecimal costJntYFour = calculateVip(costYJntNewFour, costYJntReplaceFour);
        costMap.put("jntYFour", costJntYFour);
        BigDecimal costJntYFive = calculateVip(costYJntNewFive, costYJntReplaceFive);
        costMap.put("jntYFive", costJntYFive);
        costMap.put("blankYOne", BigDecimal.ZERO);
        costMap.put("blankYTwo", BigDecimal.ZERO);
        costMap.put("blankYThree", BigDecimal.ZERO);
        costMap.put("blankYFour", BigDecimal.ZERO);
        costMap.put("blankYFive", BigDecimal.ZERO);

        costMap.put("yOne", costSmsYOne.add(costJntYOne));
        costMap.put("yTwo", costSmsYTwo.add(costJntYTwo));
        costMap.put("yThree", costSmsYThree.add(costJntYThree));
        costMap.put("yFour", costSmsYFour.add(costJntYFour));
        costMap.put("yFive", costSmsYFive.add(costJntYFive));

        // Product cost per unit
        Map<String, Object> perCostMap = new HashMap<>();
        perCostMap.put("sort", 7);
        perCostMap.put("typeName", "Product cost per unit");
        BigDecimal perCostSmsYOne = calculatePerUnits(unitsSmsYOne, costSmsYOne);
        perCostMap.put("smsYOne", perCostSmsYOne);
        BigDecimal perCostSmsYTwo = calculatePerUnits(unitsSmsYTwo, costSmsYTwo);
        perCostMap.put("smsYTwo", perCostSmsYTwo);
        BigDecimal perCostSmsYThree = calculatePerUnits(unitsSmsYThree, costSmsYThree);
        perCostMap.put("smsYThree", perCostSmsYThree);
        BigDecimal perCostSmsYFour = calculatePerUnits(unitsSmsYFour, costSmsYFour);
        perCostMap.put("smsYFour", perCostSmsYFour);
        BigDecimal perCostSmsYFive = calculatePerUnits(unitsSmsYFive, costSmsYFive);
        perCostMap.put("smsYFive", perCostSmsYFive);
        BigDecimal perCostJntYOne = calculatePerUnits(unitsJntYOne, costJntYOne);
        perCostMap.put("jntYOne", perCostJntYOne);
        BigDecimal perCostJntYTwo = calculatePerUnits(unitsJntYTwo, costJntYTwo);
        perCostMap.put("jntYTwo", perCostJntYTwo);
        BigDecimal perCostJntYThree = calculatePerUnits(unitsJntYThree, costJntYThree);
        perCostMap.put("jntYThree", perCostJntYThree);
        BigDecimal perCostJntYFour = calculatePerUnits(unitsJntYFour, costJntYFour);
        perCostMap.put("jntYFour", perCostJntYFour);
        BigDecimal perCostJntYFive = calculatePerUnits(unitsJntYFive, costJntYFive);
        perCostMap.put("jntYFive", perCostJntYFive);
        perCostMap.put("blankYOne", BigDecimal.ZERO);
        perCostMap.put("blankYTwo", BigDecimal.ZERO);
        perCostMap.put("blankYThree", BigDecimal.ZERO);
        perCostMap.put("blankYFour", BigDecimal.ZERO);
        perCostMap.put("blankYFive", BigDecimal.ZERO);


        perCostMap.put("yOne", perCostSmsYOne.add(perCostJntYOne));
        perCostMap.put("yTwo", perCostSmsYTwo.add(perCostJntYTwo));
        perCostMap.put("yThree", perCostSmsYThree.add(perCostJntYThree));
        perCostMap.put("yFour", perCostSmsYFour.add(perCostJntYFour));
        perCostMap.put("yFive", perCostSmsYFive.add(perCostJntYFive));
        profitList.add(perCostMap);

        profitList.add(costMap);

        // ODC
        Map<String, Object> odcMap = new HashMap<>();
        odcMap.put("sort", 9);
        odcMap.put("typeName", "ODC");
        BigDecimal odcSmsYOne = calculateVip(odcSmsNewOne, odcSmsReplaceOne);
        odcMap.put("smsYOne", odcSmsYOne);
        BigDecimal odcSmsYTwo = calculateVip(odcSmsNewTwo, odcSmsReplaceTwo);
        odcMap.put("smsYTwo", odcSmsYTwo);
        BigDecimal odcSmsYThree = calculateVip(odcSmsNewThree, odcSmsReplaceThree);
        odcMap.put("smsYThree", odcSmsYThree);
        BigDecimal odcSmsYFour = calculateVip(odcSmsNewFour, odcSmsReplaceFour);
        odcMap.put("smsYFour", odcSmsYFour);
        BigDecimal odcSmsYFive = calculateVip(odcSmsNewFive, odcSmsReplaceFive);
        odcMap.put("smsYFive", odcSmsYFive);
        BigDecimal odcJntYOne = calculateVip(odcJntNewOne, odcJntReplaceOne);
        odcMap.put("jntYOne", odcJntYOne);
        BigDecimal odcJntYTwo = calculateVip(odcJntNewTwo, odcJntReplaceTwo);
        odcMap.put("jntYTwo", odcJntYTwo);
        BigDecimal odcJntYThree = calculateVip(odcJntNewThree, odcJntReplaceThree);
        odcMap.put("jntYThree", odcJntYThree);
        BigDecimal odcJntYFour = calculateVip(odcJntNewFour, odcJntReplaceFour);
        odcMap.put("jntYFour", odcJntYFour);
        BigDecimal odcJntYFive = calculateVip(odcJntNewFive, odcJntReplaceFive);
        odcMap.put("jntYFive", odcJntYFive);
        odcMap.put("blankYOne", BigDecimal.ZERO);
        odcMap.put("blankYTwo", BigDecimal.ZERO);
        odcMap.put("blankYThree", BigDecimal.ZERO);
        odcMap.put("blankYFour", BigDecimal.ZERO);
        odcMap.put("blankYFive", BigDecimal.ZERO);

        BigDecimal odcYOne;
        BigDecimal odcYTwo;
        BigDecimal odcYThree;
        BigDecimal odcYFour;
        BigDecimal odcYFive;
        odcYOne = odcSmsYOne.add(odcJntYOne);
        odcYTwo = odcSmsYTwo.add(odcJntYTwo);
        odcYThree = odcSmsYThree.add(odcJntYThree);
        odcYFour = odcSmsYFour.add(odcJntYFour);
        odcYFive = odcSmsYFive.add(odcJntYFive);

        odcMap.put("yZero", calculateRate(odcYOne, netSalesYOne));
        odcMap.put("yOne", odcSmsYOne.add(odcJntYOne));
        odcMap.put("yTwo", odcYTwo);
        odcMap.put("yThree", odcYThree);
        odcMap.put("yFour", odcYFour);
        odcMap.put("yFive", odcYFive);
        profitList.add(odcMap);

        // Freight Out
        Map<String, Object> freightMap = new HashMap<>();
        freightMap.put("sort", 10);
        freightMap.put("typeName", "Freight Out");
        BigDecimal freightSmsYOne = calculateVip(freightSmsNewOne, freightSmsReplaceOne);
        freightMap.put("smsYOne", freightSmsYOne);
        BigDecimal freightSmsYTwo = calculateVip(freightSmsNewTwo, freightSmsReplaceTwo);
        freightMap.put("smsYTwo", freightSmsYTwo);
        BigDecimal freightSmsYThree = calculateVip(freightSmsNewThree, freightSmsReplaceThree);
        freightMap.put("smsYThree", freightSmsYThree);
        BigDecimal freightSmsYFour = calculateVip(freightSmsNewFour, freightSmsReplaceFour);
        freightMap.put("smsYFour", freightSmsYFour);
        BigDecimal freightSmsYFive = calculateVip(freightSmsNewFive, freightSmsReplaceFive);
        freightMap.put("smsYFive", freightSmsYFive);
        BigDecimal freightJntYOne = calculateVip(freightJntNewOne, freightJntReplaceOne);
        freightMap.put("jntYOne", freightJntYOne);
        BigDecimal freightJntYTwo = calculateVip(freightJntNewTwo, freightJntReplaceTwo);
        freightMap.put("jntYTwo", freightJntYTwo);
        BigDecimal freightJntYThree = calculateVip(freightJntNewThree, freightJntReplaceThree);
        freightMap.put("jntYThree", freightJntYThree);
        BigDecimal freightJntYFour = calculateVip(freightJntNewFour, freightJntReplaceFour);
        freightMap.put("jntYFour", freightJntYFour);
        BigDecimal freightJntYFive = calculateVip(freightJntNewFive, freightJntReplaceFive);
        freightMap.put("jntYFive", freightJntYFive);
        freightMap.put("blankYOne", BigDecimal.ZERO);
        freightMap.put("blankYTwo", BigDecimal.ZERO);
        freightMap.put("blankYThree", BigDecimal.ZERO);
        freightMap.put("blankYFour", BigDecimal.ZERO);
        freightMap.put("blankYFive", BigDecimal.ZERO);

        BigDecimal freightYOne;
        BigDecimal freightYTwo;
        BigDecimal freightYThree;
        BigDecimal freightYFour;
        BigDecimal freightYFive;
        freightYOne = freightSmsYOne.add(freightJntYOne);
        freightYTwo = freightSmsYTwo.add(freightJntYTwo);
        freightYThree = freightSmsYThree.add(freightJntYThree);
        freightYFour = freightSmsYFour.add(freightJntYFour);
        freightYFive = freightSmsYFive.add(freightJntYFive);

        freightMap.put("yZero", BigDecimal.ZERO.compareTo(netSalesYOne) == 0 ? 0 : calculateRate(freightYOne, netSalesYOne));
        freightMap.put("yOne", freightYOne);
        freightMap.put("yTwo", freightYTwo);
        freightMap.put("yThree", freightYThree);
        freightMap.put("yFour", freightYFour);
        freightMap.put("yFive", freightYFive);
        profitList.add(freightMap);

        // Total Variable cost
        Map<String, Object> variableCostMap = new HashMap<>();
        variableCostMap.put("sort", 11);
        variableCostMap.put("typeName", "Total Variable cost");
        BigDecimal variableCostSmsYOne = calculateNetSales(costSmsYOne, odcSmsYOne, freightSmsYOne);
        variableCostMap.put("smsYOne", variableCostSmsYOne);
        BigDecimal variableCostSmsYTwo = calculateNetSales(costSmsYTwo, odcSmsYTwo, freightSmsYTwo);
        variableCostMap.put("smsYTwo", variableCostSmsYTwo);
        BigDecimal variableCostSmsYThree = calculateNetSales(costSmsYThree, odcSmsYThree, freightSmsYThree);
        variableCostMap.put("smsYThree", variableCostSmsYThree);
        BigDecimal variableCostSmsYFour = calculateNetSales(costSmsYFour, odcSmsYFour, freightSmsYFour);
        variableCostMap.put("smsYFour", variableCostSmsYFour);
        BigDecimal variableCostSmsYFive = calculateNetSales(costSmsYFive, odcSmsYFive, freightSmsYFive);
        variableCostMap.put("smsYFive", variableCostSmsYFive);
        BigDecimal variableCostJntYOne = calculateNetSales(costJntYOne, odcJntYOne, freightJntYOne);
        variableCostMap.put("jntYOne", variableCostJntYOne);
        BigDecimal variableCostJntYTwo = calculateNetSales(costJntYTwo, odcJntYTwo, freightJntYTwo);
        variableCostMap.put("jntYTwo", variableCostJntYTwo);
        BigDecimal variableCostJntYThree = calculateNetSales(costJntYThree, odcJntYThree, freightJntYThree);
        variableCostMap.put("jntYThree", variableCostJntYThree);
        BigDecimal variableCostJntYFour = calculateNetSales(costJntYFour, odcJntYFour, freightJntYFour);
        variableCostMap.put("jntYFour", variableCostJntYFour);
        BigDecimal variableCostJntYFive = calculateNetSales(costJntYFive, odcJntYFive, freightJntYFive);
        variableCostMap.put("jntYFive", variableCostJntYFive);
        variableCostMap.put("blankYOne", BigDecimal.ZERO);
        variableCostMap.put("blankYTwo", BigDecimal.ZERO);
        variableCostMap.put("blankYThree", BigDecimal.ZERO);
        variableCostMap.put("blankYFour", BigDecimal.ZERO);
        variableCostMap.put("blankYFive", BigDecimal.ZERO);

        BigDecimal variableCostYOne;
        BigDecimal variableCostYTwo;
        BigDecimal variableCostYThree;
        BigDecimal variableCostYFour;
        BigDecimal variableCostYFive;
        variableCostYOne = variableCostSmsYOne.add(variableCostJntYOne);
        variableCostYTwo = variableCostSmsYTwo.add(variableCostJntYTwo);
        variableCostYThree = variableCostSmsYThree.add(variableCostJntYThree);
        variableCostYFour = variableCostSmsYFour.add(variableCostJntYFour);
        variableCostYFive = variableCostSmsYFive.add(variableCostJntYFive);

        variableCostMap.put("yOne", variableCostYOne);
        variableCostMap.put("yTwo", variableCostYTwo);
        variableCostMap.put("yThree", variableCostYThree);
        variableCostMap.put("yFour", variableCostYFour);
        variableCostMap.put("yFive", variableCostYFive);
        profitList.add(variableCostMap);

        // Standard Contribution Margin
        Map<String, Object> standardMarginMap = new HashMap<>();
        standardMarginMap.put("sort", 12);
        standardMarginMap.put("typeName", "Standard Contribution Margin");
        BigDecimal standardMarginSmsYOne = netSalesSmsYOne.add(variableCostSmsYOne);
        standardMarginMap.put("smsYOne", standardMarginSmsYOne);
        BigDecimal standardMarginSmsYTwo = netSalesSmsYTwo.add(variableCostSmsYTwo);
        standardMarginMap.put("smsYTwo", standardMarginSmsYTwo);
        BigDecimal standardMarginSmsYThree = netSalesSmsYThree.add(variableCostSmsYThree);
        standardMarginMap.put("smsYThree", standardMarginSmsYThree);
        BigDecimal standardMarginSmsYFour = netSalesSmsYFour.add(variableCostSmsYFour);
        standardMarginMap.put("smsYFour", standardMarginSmsYFour);
        BigDecimal standardMarginSmsYFive = netSalesSmsYFive.add(variableCostSmsYFive);
        standardMarginMap.put("smsYFive", standardMarginSmsYFive);
        BigDecimal standardMarginJntYOne = netSalesJntYOne.add(variableCostJntYOne);
        standardMarginMap.put("jntYOne", standardMarginJntYOne);
        BigDecimal standardMarginJntYTwo = netSalesJntYTwo.add(variableCostJntYTwo);
        standardMarginMap.put("jntYTwo", standardMarginJntYTwo);
        BigDecimal standardMarginJntYThree = netSalesJntYThree.add(variableCostJntYThree);
        standardMarginMap.put("jntYThree", standardMarginJntYThree);
        BigDecimal standardMarginJntYFour = netSalesJntYFour.add(variableCostJntYFour);
        standardMarginMap.put("jntYFour", standardMarginJntYFour);
        BigDecimal standardMarginJntYFive = netSalesJntYFive.add(variableCostJntYFive);
        standardMarginMap.put("jntYFive", standardMarginJntYFive);
        standardMarginMap.put("blankYOne", BigDecimal.ZERO);
        standardMarginMap.put("blankYTwo", BigDecimal.ZERO);
        standardMarginMap.put("blankYThree", BigDecimal.ZERO);
        standardMarginMap.put("blankYFour", BigDecimal.ZERO);
        standardMarginMap.put("blankYFive", BigDecimal.ZERO);

        standardMarginMap.put("yOne", standardMarginSmsYOne.add(standardMarginJntYOne));
        standardMarginMap.put("yTwo", standardMarginSmsYTwo.add(standardMarginJntYTwo));
        standardMarginMap.put("yThree", standardMarginSmsYThree.add(standardMarginJntYThree));
        standardMarginMap.put("yFour", standardMarginSmsYFour.add(standardMarginJntYFour));
        standardMarginMap.put("yFive", standardMarginSmsYFive.add(standardMarginJntYFive));
        profitList.add(standardMarginMap);

        BigDecimal contributionSmsYOne = new BigDecimal(String.valueOf(standardMarginSmsYOne));
        BigDecimal contributionSmsYTwo = new BigDecimal(String.valueOf(standardMarginSmsYTwo));
        BigDecimal contributionSmsYThree = new BigDecimal(String.valueOf(standardMarginSmsYThree));
        BigDecimal contributionSmsYFour = new BigDecimal(String.valueOf(standardMarginSmsYFour));
        BigDecimal contributionSmsYFive = new BigDecimal(String.valueOf(standardMarginSmsYFive));
        BigDecimal contributionJntYOne = new BigDecimal(String.valueOf(standardMarginJntYOne));
        BigDecimal contributionJntYTwo = new BigDecimal(String.valueOf(standardMarginJntYTwo));
        BigDecimal contributionJntYThree = new BigDecimal(String.valueOf(standardMarginJntYThree));
        BigDecimal contributionJntYFour = new BigDecimal(String.valueOf(standardMarginJntYFour));
        BigDecimal contributionJntYFive = new BigDecimal(String.valueOf(standardMarginJntYFive));

        BigDecimal lossRatePartSmsYOne = BigDecimal.ZERO;
        BigDecimal lossRatePartSmsYTwo = BigDecimal.ZERO;
        BigDecimal lossRatePartSmsYThree = BigDecimal.ZERO;
        BigDecimal lossRatePartSmsYFour = BigDecimal.ZERO;
        BigDecimal lossRatePartSmsYFive = BigDecimal.ZERO;
        BigDecimal lossRatePartJntYOne = BigDecimal.ZERO;
        BigDecimal lossRatePartJntYTwo = BigDecimal.ZERO;
        BigDecimal lossRatePartJntYThree = BigDecimal.ZERO;
        BigDecimal lossRatePartJntYFour = BigDecimal.ZERO;
        BigDecimal lossRatePartJntYFive = BigDecimal.ZERO;

        BigDecimal lossRateTotalSmsYOne = BigDecimal.ZERO;
        BigDecimal lossRateTotalSmsYTwo = BigDecimal.ZERO;
        BigDecimal lossRateTotalSmsYThree = BigDecimal.ZERO;
        BigDecimal lossRateTotalSmsYFour = BigDecimal.ZERO;
        BigDecimal lossRateTotalSmsYFive = BigDecimal.ZERO;
        BigDecimal lossRateTotalJntYOne = BigDecimal.ZERO;
        BigDecimal lossRateTotalJntYTwo = BigDecimal.ZERO;
        BigDecimal lossRateTotalJntYThree = BigDecimal.ZERO;
        BigDecimal lossRateTotalJntYFour = BigDecimal.ZERO;
        BigDecimal lossRateTotalJntYFive = BigDecimal.ZERO;
        // Sales commissions
        // Service and Warranty
        List<InvestmentLossRate> lossRateList = calculateDataDto.getLossRateData();
        for (InvestmentLossRate lossRate : lossRateList) {
            Map<String, Object> lossRateMap = new HashMap<>();
            if (lossRate.getRateType() < 3) {
                lossRateMap.put("sort", lossRate.getRateType() + 12);
            } else {
                lossRateMap.put("sort", lossRate.getRateType() + 14);
            }
            lossRateMap.put("typeName", InvestmentLossRateEnum.getNameByValue(lossRate.getRateType()));
            BigDecimal lossRateSmsYOne = calculateSalesLoss(netSalesSmsYOne, new BigDecimal(ObjectUtils.isEmpty(lossRate.getRateAmountSms()) ? "0" : lossRate.getRateAmountSms()));
            lossRateMap.put("smsYOne", lossRateSmsYOne);
            BigDecimal lossRateSmsYTwo = calculateSalesLoss(netSalesSmsYTwo, new BigDecimal(ObjectUtils.isEmpty(lossRate.getRateAmountSms()) ? "0" : lossRate.getRateAmountSms()));
            lossRateMap.put("smsYTwo", lossRateSmsYTwo);
            BigDecimal lossRateSmsYThree = calculateSalesLoss(netSalesSmsYThree, new BigDecimal(ObjectUtils.isEmpty(lossRate.getRateAmountSms()) ? "0" : lossRate.getRateAmountSms()));
            lossRateMap.put("smsYThree", lossRateSmsYThree);
            BigDecimal lossRateSmsYFour = calculateSalesLoss(netSalesSmsYFour, new BigDecimal(ObjectUtils.isEmpty(lossRate.getRateAmountSms()) ? "0" : lossRate.getRateAmountSms()));
            lossRateMap.put("smsYFour", lossRateSmsYFour);
            BigDecimal lossRateSmsYFive = calculateSalesLoss(netSalesSmsYFive, new BigDecimal(ObjectUtils.isEmpty(lossRate.getRateAmountSms()) ? "0" : lossRate.getRateAmountSms()));
            lossRateMap.put("smsYFive", lossRateSmsYFive);
            BigDecimal lossRateJntYOne = calculateSalesLoss(netSalesJntYOne, new BigDecimal(ObjectUtils.isEmpty(lossRate.getRateAmountJnt()) ? "0" : lossRate.getRateAmountJnt()));
            lossRateMap.put("jntYOne", lossRateJntYOne);
            BigDecimal lossRateJntYTwo = calculateSalesLoss(netSalesJntYTwo, new BigDecimal(ObjectUtils.isEmpty(lossRate.getRateAmountJnt()) ? "0" : lossRate.getRateAmountJnt()));
            lossRateMap.put("jntYTwo", lossRateJntYTwo);
            BigDecimal lossRateJntYThree = calculateSalesLoss(netSalesJntYThree, new BigDecimal(ObjectUtils.isEmpty(lossRate.getRateAmountJnt()) ? "0" : lossRate.getRateAmountJnt()));
            lossRateMap.put("jntYThree", lossRateJntYThree);
            BigDecimal lossRateJntYFour = calculateSalesLoss(netSalesJntYFour, new BigDecimal(ObjectUtils.isEmpty(lossRate.getRateAmountJnt()) ? "0" : lossRate.getRateAmountJnt()));
            lossRateMap.put("jntYFour", lossRateJntYFour);
            BigDecimal lossRateJntYFive = calculateSalesLoss(netSalesJntYFive, new BigDecimal(ObjectUtils.isEmpty(lossRate.getRateAmountJnt()) ? "0" : lossRate.getRateAmountJnt()));
            lossRateMap.put("jntYFive", lossRateJntYFive);
            lossRateMap.put("blankYOne", BigDecimal.ZERO);
            lossRateMap.put("blankYTwo", BigDecimal.ZERO);
            lossRateMap.put("blankYThree", BigDecimal.ZERO);
            lossRateMap.put("blankYFour", BigDecimal.ZERO);
            lossRateMap.put("blankYFive", BigDecimal.ZERO);

            BigDecimal lossRateYOne;
            BigDecimal lossRateYTwo;
            BigDecimal lossRateYThree;
            BigDecimal lossRateYFour;
            BigDecimal lossRateYFive;
            lossRateYOne = lossRateSmsYOne.add(lossRateJntYOne);
            lossRateYTwo = lossRateSmsYTwo.add(lossRateJntYTwo);
            lossRateYThree = lossRateSmsYThree.add(lossRateJntYThree);
            lossRateYFour = lossRateSmsYFour.add(lossRateJntYFour);
            lossRateYFive = lossRateSmsYFive.add(lossRateJntYFive);

            lossRateMap.put("yZero", calculateRate(lossRateYOne, netSalesYOne));
            lossRateMap.put("yOne", lossRateYOne);
            lossRateMap.put("yTwo", lossRateYTwo);
            lossRateMap.put("yThree", lossRateYThree);
            lossRateMap.put("yFour", lossRateYFour);
            lossRateMap.put("yFive", lossRateYFive);
            profitList.add(lossRateMap);
            if (lossRate.getRateType() == InvestmentLossRateEnum.SALES.getValue() ||
                    lossRate.getRateType() == InvestmentLossRateEnum.SERVICE.getValue()) {
                contributionSmsYOne = contributionSmsYOne.add(lossRateSmsYOne);
                contributionSmsYTwo = contributionSmsYTwo.add(lossRateSmsYTwo);
                contributionSmsYThree = contributionSmsYThree.add(lossRateSmsYThree);
                contributionSmsYFour = contributionSmsYFour.add(lossRateSmsYFour);
                contributionSmsYFive = contributionSmsYFive.add(lossRateSmsYFive);
                contributionJntYOne = contributionJntYOne.add(lossRateJntYOne);
                contributionJntYTwo = contributionJntYTwo.add(lossRateJntYTwo);
                contributionJntYThree = contributionJntYThree.add(lossRateJntYThree);
                contributionJntYFour = contributionJntYFour.add(lossRateJntYFour);
                contributionJntYFive = contributionJntYFive.add(lossRateJntYFive);
            } else if (lossRate.getRateType() > InvestmentLossRateEnum.SERVICE.getValue()) {
                lossRatePartSmsYOne = lossRatePartSmsYOne.add(lossRateSmsYOne);
                lossRatePartSmsYTwo = lossRatePartSmsYTwo.add(lossRateSmsYTwo);
                lossRatePartSmsYThree = lossRatePartSmsYThree.add(lossRateSmsYThree);
                lossRatePartSmsYFour = lossRatePartSmsYFour.add(lossRateSmsYFour);
                lossRatePartSmsYFive = lossRatePartSmsYFive.add(lossRateSmsYFive);
                lossRatePartJntYOne = lossRatePartJntYOne.add(lossRateJntYOne);
                lossRatePartJntYTwo = lossRatePartJntYTwo.add(lossRateJntYTwo);
                lossRatePartJntYThree = lossRatePartJntYThree.add(lossRateJntYThree);
                lossRatePartJntYFour = lossRatePartJntYFour.add(lossRateJntYFour);
                lossRatePartJntYFive = lossRatePartJntYFive.add(lossRateJntYFive);
            }
            lossRateTotalSmsYOne = lossRateTotalSmsYOne.add(lossRateSmsYOne);
            lossRateTotalSmsYTwo = lossRateTotalSmsYTwo.add(lossRateSmsYTwo);
            lossRateTotalSmsYThree = lossRateTotalSmsYThree.add(lossRateSmsYThree);
            lossRateTotalSmsYFour = lossRateTotalSmsYFour.add(lossRateSmsYFour);
            lossRateTotalSmsYFive = lossRateTotalSmsYFive.add(lossRateSmsYFive);
            lossRateTotalJntYOne = lossRateTotalJntYOne.add(lossRateJntYOne);
            lossRateTotalJntYTwo = lossRateTotalJntYTwo.add(lossRateJntYTwo);
            lossRateTotalJntYThree = lossRateTotalJntYThree.add(lossRateJntYThree);
            lossRateTotalJntYFour = lossRateTotalJntYFour.add(lossRateJntYFour);
            lossRateTotalJntYFive = lossRateTotalJntYFive.add(lossRateJntYFive);
        }
        // Actual Contribution
        Map<String, Object> contributionMap = new HashMap<>();
        contributionMap.put("sort", 15);
        contributionMap.put("typeName", "Actual Contribution");

        contributionMap.put("smsYOne", contributionSmsYOne);
        contributionMap.put("smsYTwo", contributionSmsYTwo);
        contributionMap.put("smsYThree", contributionSmsYThree);
        contributionMap.put("smsYFour", contributionSmsYFour);
        contributionMap.put("smsYFive", contributionSmsYFive);
        contributionMap.put("jntYOne", contributionJntYOne);
        contributionMap.put("jntYTwo", contributionJntYTwo);
        contributionMap.put("jntYThree", contributionJntYThree);
        contributionMap.put("jntYFour", contributionJntYFour);
        contributionMap.put("jntYFive", contributionJntYFive);
        contributionMap.put("blankYOne", BigDecimal.ZERO);
        contributionMap.put("blankYTwo", BigDecimal.ZERO);
        contributionMap.put("blankYThree", BigDecimal.ZERO);
        contributionMap.put("blankYFour", BigDecimal.ZERO);
        contributionMap.put("blankYFive", BigDecimal.ZERO);

        contributionMap.put("yOne", contributionSmsYOne.add(contributionJntYOne));
        contributionMap.put("yTwo", contributionSmsYTwo.add(contributionJntYTwo));
        contributionMap.put("yThree", contributionSmsYThree.add(contributionJntYThree));
        contributionMap.put("yFour", contributionSmsYFour.add(contributionJntYFour));
        contributionMap.put("yFive", contributionSmsYFive.add(contributionJntYFive));
        profitList.add(contributionMap);

        // Actual Contribution %
        Map<String, Object> contributionRateMap = new HashMap<>();
        contributionRateMap.put("sort", 16);
        contributionRateMap.put("typeName", "Actual Contribution %");
        contributionRateMap.put("smsYOne", calculateContributionRate(netSalesSmsYOne, contributionSmsYOne));
        contributionRateMap.put("smsYTwo", calculateContributionRate(netSalesSmsYTwo, contributionSmsYTwo));
        contributionRateMap.put("smsYThree", calculateContributionRate(netSalesSmsYThree, contributionSmsYThree));
        contributionRateMap.put("smsYFour", calculateContributionRate(netSalesSmsYFour, contributionSmsYFour));
        contributionRateMap.put("smsYFive", calculateContributionRate(netSalesSmsYFive, contributionSmsYFive));
        contributionRateMap.put("jntYOne", calculateContributionRate(netSalesJntYOne, contributionJntYOne));
        contributionRateMap.put("jntYTwo", calculateContributionRate(netSalesJntYTwo, contributionJntYTwo));
        contributionRateMap.put("jntYThree", calculateContributionRate(netSalesJntYThree, contributionJntYThree));
        contributionRateMap.put("jntYFour", calculateContributionRate(netSalesJntYFour, contributionJntYFour));
        contributionRateMap.put("jntYFive", calculateContributionRate(netSalesJntYFive, contributionJntYFive));
        contributionRateMap.put("blankYOne", BigDecimal.ZERO);
        contributionRateMap.put("blankYTwo", BigDecimal.ZERO);
        contributionRateMap.put("blankYThree", BigDecimal.ZERO);
        contributionRateMap.put("blankYFour", BigDecimal.ZERO);
        contributionRateMap.put("blankYFive", BigDecimal.ZERO);

        contributionRateMap.put("yOne", calculateContributionRate(netSalesSmsYOne.add(netSalesJntYOne), contributionSmsYOne.add(contributionJntYOne)));
        contributionRateMap.put("yTwo", calculateContributionRate(netSalesSmsYTwo.add(netSalesJntYTwo), contributionSmsYTwo.add(contributionJntYTwo)));
        contributionRateMap.put("yThree", calculateContributionRate(netSalesSmsYThree.add(netSalesJntYThree), contributionSmsYThree.add(contributionJntYThree)));
        contributionRateMap.put("yFour", calculateContributionRate(netSalesSmsYFour.add(netSalesJntYFour), contributionSmsYFour.add(contributionJntYFour)));
        contributionRateMap.put("yFive", calculateContributionRate(netSalesSmsYFive.add(netSalesJntYFive), contributionSmsYFive.add(contributionJntYFive)));
        profitList.add(contributionRateMap);

        // EBIT impact (from growth)
        Map<String, Object> ebitMap = new HashMap<>();
        ebitMap.put("sort", 22);
        ebitMap.put("typeName", "EBIT impact (from growth)");
        BigDecimal ebitSmsYOne = contributionSmsYOne.add(lossRatePartSmsYOne);
        BigDecimal ebitSmsYTwo = contributionSmsYTwo.add(lossRatePartSmsYTwo);
        BigDecimal ebitSmsYThree = contributionSmsYThree.add(lossRatePartSmsYThree);
        BigDecimal ebitSmsYFour = contributionSmsYFour.add(lossRatePartSmsYFour);
        BigDecimal ebitSmsYFive = contributionSmsYFive.add(lossRatePartSmsYFive);
        BigDecimal ebitJntYOne = contributionJntYOne.add(lossRatePartJntYOne);
        BigDecimal ebitJntYTwo = contributionJntYTwo.add(lossRatePartJntYTwo);
        BigDecimal ebitJntYThree = contributionJntYThree.add(lossRatePartJntYThree);
        BigDecimal ebitJntYFour = contributionJntYFour.add(lossRatePartJntYFour);
        BigDecimal ebitJntYFive = contributionJntYFive.add(lossRatePartJntYFive);
        ebitMap.put("smsYOne", ebitSmsYOne);
        ebitMap.put("smsYTwo", ebitSmsYTwo);
        ebitMap.put("smsYThree", ebitSmsYThree);
        ebitMap.put("smsYFour", ebitSmsYFour);
        ebitMap.put("smsYFive", ebitSmsYFive);
        ebitMap.put("jntYOne", ebitJntYOne);
        ebitMap.put("jntYTwo", ebitJntYTwo);
        ebitMap.put("jntYThree", ebitJntYThree);
        ebitMap.put("jntYFour", ebitJntYFour);
        ebitMap.put("jntYFive", ebitJntYFive);
        ebitMap.put("blankYOne", BigDecimal.ZERO);
        ebitMap.put("blankYTwo", BigDecimal.ZERO);
        ebitMap.put("blankYThree", BigDecimal.ZERO);
        ebitMap.put("blankYFour", BigDecimal.ZERO);
        ebitMap.put("blankYFive", BigDecimal.ZERO);

        ebitMap.put("yOne", ebitSmsYOne.add(ebitJntYOne));
        ebitMap.put("yTwo", ebitSmsYTwo.add(ebitJntYTwo));
        ebitMap.put("yThree", ebitSmsYThree.add(ebitJntYThree));
        ebitMap.put("yFour", ebitSmsYFour.add(ebitJntYFour));
        ebitMap.put("yFive", ebitSmsYFive.add(ebitJntYFive));
        profitList.add(ebitMap);

        // Total expenses
        Map<String, Object> totalExpensesMap = new HashMap<>();
        totalExpensesMap.put("sort", 23);
        totalExpensesMap.put("typeName", "Total expenses");
        BigDecimal totalExpensesSmsYOne = vipSmsYOne.add(discountSmsYOne).add(variableCostSmsYOne).add(lossRateTotalSmsYOne);
        BigDecimal totalExpensesSmsYTwo = vipSmsYTwo.add(discountSmsYTwo).add(variableCostSmsYTwo).add(lossRateTotalSmsYTwo);
        BigDecimal totalExpensesSmsYThree = vipSmsYThree.add(discountSmsYThree).add(variableCostSmsYThree).add(lossRateTotalSmsYThree);
        BigDecimal totalExpensesSmsYFour = vipSmsYOne.add(discountSmsYFour).add(variableCostSmsYFour).add(lossRateTotalSmsYFour);
        BigDecimal totalExpensesSmsYFive = vipSmsYOne.add(discountSmsYFive).add(variableCostSmsYFive).add(lossRateTotalSmsYFive);
        BigDecimal totalExpensesJntYOne = vipJntYOne.add(discountJntYOne).add(variableCostJntYOne).add(lossRateTotalJntYOne);
        BigDecimal totalExpensesJntYTwo = vipJntYTwo.add(discountJntYTwo).add(variableCostJntYTwo).add(lossRateTotalJntYTwo);
        BigDecimal totalExpensesJntYThree = vipJntYThree.add(discountJntYThree).add(variableCostJntYThree).add(lossRateTotalJntYThree);
        BigDecimal totalExpensesJntYFour = vipJntYFour.add(discountJntYFour).add(variableCostJntYFour).add(lossRateTotalJntYFour);
        BigDecimal totalExpensesJntYFive = vipJntYFive.add(discountJntYFive).add(variableCostJntYFive).add(lossRateTotalJntYFive);
        totalExpensesMap.put("smsYOne", totalExpensesSmsYOne);
        totalExpensesMap.put("smsYTwo", totalExpensesSmsYTwo);
        totalExpensesMap.put("smsYThree", totalExpensesSmsYThree);
        totalExpensesMap.put("smsYFour", totalExpensesSmsYFour);
        totalExpensesMap.put("smsYFive", totalExpensesSmsYFive);
        totalExpensesMap.put("jntYOne", totalExpensesJntYOne);
        totalExpensesMap.put("jntYTwo", totalExpensesJntYTwo);
        totalExpensesMap.put("jntYThree", totalExpensesJntYThree);
        totalExpensesMap.put("jntYFour", totalExpensesJntYFour);
        totalExpensesMap.put("jntYFive", totalExpensesJntYFive);
        totalExpensesMap.put("blankYOne", BigDecimal.ZERO);
        totalExpensesMap.put("blankYTwo", BigDecimal.ZERO);
        totalExpensesMap.put("blankYThree", BigDecimal.ZERO);
        totalExpensesMap.put("blankYFour", BigDecimal.ZERO);
        totalExpensesMap.put("blankYFive", BigDecimal.ZERO);

        BigDecimal totalExpensesYOne;
        BigDecimal totalExpensesYTwo;
        BigDecimal totalExpensesYThree;
        BigDecimal totalExpensesYFour;
        BigDecimal totalExpensesYFive;
        totalExpensesYOne = totalExpensesSmsYOne.add(totalExpensesJntYOne);
        totalExpensesYTwo = totalExpensesSmsYTwo.add(totalExpensesJntYTwo);
        totalExpensesYThree = totalExpensesSmsYThree.add(totalExpensesJntYThree);
        totalExpensesYFour = totalExpensesSmsYFour.add(totalExpensesJntYFour);
        totalExpensesYFive = totalExpensesSmsYFive.add(totalExpensesJntYFive);

        totalExpensesMap.put("yOne", totalExpensesYOne);
        totalExpensesMap.put("yTwo", totalExpensesYTwo);
        totalExpensesMap.put("yThree", totalExpensesYThree);
        totalExpensesMap.put("yFour", totalExpensesYFour);
        totalExpensesMap.put("yFive", totalExpensesYFive);
        profitList.add(totalExpensesMap);

        List<Map<String, Object>> sortProfitList = profitList.stream().sorted(Comparator.comparing((Map<String, Object> h) -> (Integer) h.get("sort"))).collect(Collectors.toList());
        profitMap.put("profitList", sortProfitList);

        List<Map<String, Object>> capitalList = new ArrayList<>();
        List<InvestmentTurnover> turnoverList = calculateDataDto.getTurnoverData();
        for (InvestmentCapitalEnum capital : InvestmentCapitalEnum.values()) {
            Map<String, Object> item = new HashMap<>();
            item.put("sort", capital.getValue());
            item.put("typeName", capital.getName());
            BigDecimal yOne = BigDecimal.ZERO;
            BigDecimal yTwo = BigDecimal.ZERO;
            BigDecimal yThree = BigDecimal.ZERO;
            BigDecimal yFour = BigDecimal.ZERO;
            BigDecimal yFive = BigDecimal.ZERO;
            if (capital.getValue() == InvestmentCapitalEnum.AR.getValue()
                    || capital.getValue() == InvestmentCapitalEnum.INVENTORY.getValue()
                    || capital.getValue() == InvestmentCapitalEnum.AP.getValue()) {
                InvestmentTurnover arTurnover = turnoverList.stream().filter(turnover -> turnover.getTurnoverType() == capital.getValue()).collect(Collectors.toList()).get(0);
                yOne = BigDecimal.valueOf(arTurnover.getDays());
                yTwo = BigDecimal.valueOf(arTurnover.getDays());
                yThree = BigDecimal.valueOf(arTurnover.getDays());
                yFour = BigDecimal.valueOf(arTurnover.getDays());
                yFive = BigDecimal.valueOf(arTurnover.getDays());
            } else if (capital.getValue() == InvestmentCapitalEnum.RECEIVABLE_AMOUNT.getValue()) {
                InvestmentTurnover arTurnover = turnoverList.stream().filter(turnover -> turnover.getTurnoverType() == InvestmentCapitalEnum.AR.getValue()).collect(Collectors.toList()).get(0);
                yOne = calculateDayAmount(nisYOne, BigDecimal.valueOf(arTurnover.getDays()));
                yTwo = calculateDayAmount(nisYTwo, BigDecimal.valueOf(arTurnover.getDays()));
                yThree = calculateDayAmount(nisYThree, BigDecimal.valueOf(arTurnover.getDays()));
                yFour = calculateDayAmount(nisYFour, BigDecimal.valueOf(arTurnover.getDays()));
                yFive = calculateDayAmount(nisYFive, BigDecimal.valueOf(arTurnover.getDays()));
            } else if (capital.getValue() == InvestmentCapitalEnum.INVENTORY_AMOUNT.getValue()) {
                InvestmentTurnover arTurnover = turnoverList.stream().filter(turnover -> turnover.getTurnoverType() == InvestmentCapitalEnum.INVENTORY.getValue()).collect(Collectors.toList()).get(0);
                yOne = calculateDayAmount(nisYOne.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yTwo = calculateDayAmount(nisYTwo.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yThree = calculateDayAmount(nisYThree.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yFour = calculateDayAmount(nisYFour.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yFive = calculateDayAmount(nisYFive.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
            } else if (capital.getValue() == InvestmentCapitalEnum.PAYABLE_AMOUNT.getValue()) {
                InvestmentTurnover arTurnover = turnoverList.stream().filter(turnover -> turnover.getTurnoverType() == InvestmentCapitalEnum.AP.getValue()).collect(Collectors.toList()).get(0);
                yOne = calculateDayAmount(nisYOne.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yTwo = calculateDayAmount(nisYTwo.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yThree = calculateDayAmount(nisYThree.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yFour = calculateDayAmount(nisYFour.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yFive = calculateDayAmount(nisYFive.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
            } else if (capital.getValue() == InvestmentCapitalEnum.ACCOUNTS_RECEIVABLE.getValue()) {
                InvestmentTurnover arTurnover = turnoverList.stream().filter(turnover -> turnover.getTurnoverType() == InvestmentCapitalEnum.AR.getValue()).collect(Collectors.toList()).get(0);
                yOne = calculateDayAmount(nisYOne.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yTwo = calculateDayAmount(nisYTwo.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yThree = calculateDayAmount(nisYThree.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yFour = calculateDayAmount(nisYFour.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yFive = calculateDayAmount(nisYFive.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
            } else if (capital.getValue() == InvestmentCapitalEnum.INVENTORY_DECREASE.getValue()) {
                InvestmentTurnover arTurnover = turnoverList.stream().filter(turnover -> turnover.getTurnoverType() == InvestmentCapitalEnum.INVENTORY.getValue()).collect(Collectors.toList()).get(0);
                yOne = calculateDayAmount(nisYOne, BigDecimal.valueOf(arTurnover.getDays()));
                yTwo = calculateDayAmount(nisYTwo, BigDecimal.valueOf(arTurnover.getDays()));
                yThree = calculateDayAmount(nisYThree, BigDecimal.valueOf(arTurnover.getDays()));
                yFour = calculateDayAmount(nisYFour, BigDecimal.valueOf(arTurnover.getDays()));
                yFive = calculateDayAmount(nisYFive, BigDecimal.valueOf(arTurnover.getDays()));
            } else if (capital.getValue() == InvestmentCapitalEnum.ACCOUNTS_PAYABLE.getValue()) {
                InvestmentTurnover arTurnover = turnoverList.stream().filter(turnover -> turnover.getTurnoverType() == InvestmentCapitalEnum.AP.getValue()).collect(Collectors.toList()).get(0);
                yOne = calculateDayAmount(nisYOne.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yTwo = calculateDayAmount(nisYTwo.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yThree = calculateDayAmount(nisYThree.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yFour = calculateDayAmount(nisYFour.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
                yFive = calculateDayAmount(nisYFive.multiply(new BigDecimal(-1)), BigDecimal.valueOf(arTurnover.getDays()));
            } else if (capital.getValue() == InvestmentCapitalEnum.IMPACT_BETTER.getValue()) {

            } else if (capital.getValue() == InvestmentCapitalEnum.CAPITALIZED_ASSETS.getValue()) {
                BigDecimal totalAmount = (BigDecimal) depreciationMap.get("totalAmount");
                BigDecimal assetsAmount = totalAmount.divide(new BigDecimal(1000), 6, RoundingMode.HALF_UP);
                yOne = assetsAmount;
                yTwo = assetsAmount;
                yThree = assetsAmount;
                yFour = assetsAmount;
                yFive = assetsAmount;
            } else if (capital.getValue() == InvestmentCapitalEnum.ACCUMULATED.getValue()) {

            } else if (capital.getValue() == InvestmentCapitalEnum.NET_WORKING.getValue()) {

            }

            item.put("yOne", yOne);
            item.put("yTwo", yTwo);
            item.put("yThree", yThree);
            item.put("yFour", yFour);
            item.put("yFive", yFive);
            capitalList.add(item);
        }
        List<Map<String, Object>> sortCapitalList = capitalList.stream().sorted(Comparator.comparing((Map<String, Object> h) -> (Integer) h.get("sort"))).collect(Collectors.toList());
        profitMap.put("capitalList", sortCapitalList);
        dataMap.put("profitMap", profitMap);

        // Par
        List<InvestmentOtherExpenses> otherList = calculateDataDto.getExpensesData();
        Map<String, Object> parMap = new HashMap<>();
//        List<InvestmentPar> parList = new ArrayList<>();
//        if (!StringUtils.isEmpty(calculateDataDto.getId())) {
//            Map<String, Object> queryParParam = new HashMap<>();
//            queryParParam.put("investmentId", calculateDataDto.getId());
//            queryParParam.put("startNum", 0);
//            queryParParam.put("pageSize", 10000);
//            parList = investmentParDao.pageInvestmentParInfo(queryParParam);
//        }
        List<Map<String, Object>> parList = new ArrayList<>();
        for (InvestmentParEnum par : InvestmentParEnum.values()) {
            Map<String, Object> item = new HashMap<>();
            item.put("sort", par.getValue());
            item.put("parName", par.getName());
            BigDecimal parZero = BigDecimal.ZERO;
            BigDecimal parOne = BigDecimal.ZERO;
            BigDecimal parTwo = BigDecimal.ZERO;
            BigDecimal parThree = BigDecimal.ZERO;
            BigDecimal parFour = BigDecimal.ZERO;
            BigDecimal parFive = BigDecimal.ZERO;
            if (par.getValue() == InvestmentParEnum.CAPITAL_EXPENDITURES.getValue()) {
                BigDecimal totalAmount = (BigDecimal) depreciationMap.get("totalAmount");
                parZero = calculateThousandNegative(totalAmount);
            } else if (par.getValue() == InvestmentParEnum.EXPENSE_SALARY.getValue()) {
                List<InvestmentOtherExpenses> salaryList = otherList.stream().filter(other -> Integer.valueOf(other.getExpensesType()) == InvestmentExpensesEnum.SALARY.getValue()).collect(Collectors.toList());
                BigDecimal salary = salaryList.size() > 0 ? new BigDecimal(salaryList.get(0).getExpensesAmount()) : BigDecimal.ZERO;
                parZero = calculateThousandNegative(salary);
            } else if (par.getValue() == InvestmentParEnum.EXPENSE_OTHER.getValue()) {
                List<InvestmentOtherExpenses> salaryList = otherList.stream().filter(other -> Integer.valueOf(other.getExpensesType()) == InvestmentExpensesEnum.OTHER.getValue()).collect(Collectors.toList());
                BigDecimal salary = salaryList.size() > 0 ? new BigDecimal(salaryList.get(0).getExpensesAmount()) : BigDecimal.ZERO;
                parZero = calculateThousandNegative(salary);
            }  else if (par.getValue() == InvestmentParEnum.TOTAL_CASH.getValue()) {
                BigDecimal totalAmount = (BigDecimal) depreciationMap.get("totalAmount");
                BigDecimal capital = calculateThousandNegative(totalAmount);
                List<InvestmentOtherExpenses> salaryList = otherList.stream().filter(other -> Integer.valueOf(other.getExpensesType()) == InvestmentExpensesEnum.SALARY.getValue()).collect(Collectors.toList());
                BigDecimal salary = salaryList.size() > 0 ? new BigDecimal(salaryList.get(0).getExpensesAmount()) : BigDecimal.ZERO;
                BigDecimal expenseSalary = calculateThousandNegative(salary);
                List<InvestmentOtherExpenses> otherExpList = otherList.stream().filter(other -> Integer.valueOf(other.getExpensesType()) == InvestmentExpensesEnum.OTHER.getValue()).collect(Collectors.toList());
                BigDecimal other = otherExpList.size() > 0 ? new BigDecimal(otherExpList.get(0).getExpensesAmount()) : BigDecimal.ZERO;
                BigDecimal expenseOther = calculateThousandNegative(other);
                parZero = capital.add(expenseSalary).add(expenseOther);
            }  else if (par.getValue() == InvestmentParEnum.CUMULATIVE_CASH.getValue()) {
                BigDecimal totalAmount = (BigDecimal) depreciationMap.get("totalAmount");
                BigDecimal capital = calculateThousandNegative(totalAmount);
                List<InvestmentOtherExpenses> salaryList = otherList.stream().filter(other -> Integer.valueOf(other.getExpensesType()) == InvestmentExpensesEnum.SALARY.getValue()).collect(Collectors.toList());
                BigDecimal salary = salaryList.size() > 0 ? new BigDecimal(salaryList.get(0).getExpensesAmount()) : BigDecimal.ZERO;
                BigDecimal expenseSalary = calculateThousandNegative(salary);
                List<InvestmentOtherExpenses> otherExpList = otherList.stream().filter(other -> Integer.valueOf(other.getExpensesType()) == InvestmentExpensesEnum.OTHER.getValue()).collect(Collectors.toList());
                BigDecimal other = otherExpList.size() > 0 ? new BigDecimal(otherExpList.get(0).getExpensesAmount()) : BigDecimal.ZERO;
                BigDecimal expenseOther = calculateThousandNegative(other);
                parZero = capital.add(expenseSalary).add(expenseOther);
            } else if (par.getValue() == InvestmentParEnum.GROWTH_VOLUME.getValue()) {
                parOne = unitsYOne.multiply(BigDecimal.valueOf(1000));
                parTwo = unitsYTwo.multiply(BigDecimal.valueOf(1000));
                parThree = unitsYThree.multiply(BigDecimal.valueOf(1000));
                parFour = unitsYFour.multiply(BigDecimal.valueOf(1000));
                parFive = unitsYFive.multiply(BigDecimal.valueOf(1000));
            } else if (par.getValue() == InvestmentParEnum.NET_INCREMENTAL.getValue()) {
                parOne = nisYOne;
                parTwo = nisYTwo;
                parThree = nisYThree;
                parFour = nisYFour;
                parFive = nisYFive;
            } else if (par.getValue() == InvestmentParEnum.TOTAL_EXPENSES.getValue()) {
                parOne = totalExpensesYOne;
                parTwo = totalExpensesYTwo;
                parThree = totalExpensesYThree;
                parFour = totalExpensesYFour;
                parFive = totalExpensesYFive;
            } else if (par.getValue() == InvestmentParEnum.BOOK.getValue()) {
                Map<String,Object> bookSummaryMap = (Map<String, Object>) depreciationMap.get("bookSummary");
                parOne = calculateThousandNegative((BigDecimal) bookSummaryMap.get("depOneTotal"));
                parTwo = calculateThousandNegative((BigDecimal) bookSummaryMap.get("depTwoTotal"));
                parThree = calculateThousandNegative((BigDecimal) bookSummaryMap.get("depThreeTotal"));
                parFour = calculateThousandNegative((BigDecimal) bookSummaryMap.get("depFourTotal"));
                parFive =calculateThousandNegative ((BigDecimal) bookSummaryMap.get("depFiveTotal"));
            } else if (par.getValue() == InvestmentParEnum.INCREMENTAL_PERFORMANCE.getValue()) {
                Map<String,Object> bookSummaryMap = (Map<String, Object>) depreciationMap.get("bookSummary");
                parOne = calculateThousandNegative((BigDecimal) bookSummaryMap.get("depOneTotal")).add(nisYOne).add(totalExpensesYOne);
                parTwo = calculateThousandNegative((BigDecimal) bookSummaryMap.get("depTwoTotal")).add(nisYTwo).add(totalExpensesYTwo);
                parThree = calculateThousandNegative((BigDecimal) bookSummaryMap.get("depThreeTotal")).add(nisYThree).add(totalExpensesYThree);
                parFour = calculateThousandNegative((BigDecimal) bookSummaryMap.get("depFourTotal")).add(nisYFour).add(totalExpensesYFour);
                parFive = calculateThousandNegative((BigDecimal) bookSummaryMap.get("depFiveTotal")).add(nisYFive).add(totalExpensesYFive);
            } else if (par.getValue() == InvestmentParEnum.NON_CASH.getValue()) {
                parOne =nisYOne.add(totalExpensesYOne);
                parTwo = nisYTwo.add(totalExpensesYTwo);
                parThree = nisYThree.add(totalExpensesYThree);
                parFour = nisYFour.add(totalExpensesYFour);
                parFive = nisYFive.add(totalExpensesYFive);
            } else if (par.getValue() == InvestmentParEnum.TAX_DEPRECIATION.getValue()) {
                Map<String,Object> taxSummaryMap = (Map<String, Object>) depreciationMap.get("taxSummary");
                parOne = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depOneTotal"));
                parTwo = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depTwoTotal"));
                parThree = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depThreeTotal"));
                parFour = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depFourTotal"));
                parFive = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depFiveTotal"));
            } else if (par.getValue() == InvestmentParEnum.TAX_BASIS.getValue()){
                Map<String,Object> taxSummaryMap = (Map<String, Object>) depreciationMap.get("taxSummary");
                parOne = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depOneTotal")).add(nisYOne).add(totalExpensesYOne);
                parTwo = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depTwoTotal")).add(nisYTwo).add(totalExpensesYTwo);
                parThree = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depThreeTotal")).add(nisYThree).add(totalExpensesYThree);
                parFour = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depFourTotal")).add(nisYFour).add(totalExpensesYFour);
                parFive = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depFiveTotal")).add(nisYFive).add(totalExpensesYFive);
            } else if (par.getValue() == InvestmentParEnum.INCREMENTAL_TAX.getValue()) {
                Map<String,Object> taxSummaryMap = (Map<String, Object>) depreciationMap.get("taxSummary");
                BigDecimal taxOne = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depOneTotal")).add(nisYOne).add(totalExpensesYOne);
                BigDecimal taxTwo = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depTwoTotal")).add(nisYTwo).add(totalExpensesYTwo);
                BigDecimal taxThree = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depThreeTotal")).add(nisYThree).add(totalExpensesYThree);
                BigDecimal taxFour = calculateThousandNegative((BigDecimal) taxSummaryMap.get("depFourTotal")).add(nisYFour).add(totalExpensesYFour);
                BigDecimal taxFive =  calculateThousandNegative((BigDecimal) taxSummaryMap.get("depFiveTotal")).add(nisYFive).add(totalExpensesYFive);
                parOne = taxOne.multiply(new BigDecimal("-0.15"));
                parTwo = taxTwo.multiply(new BigDecimal("-0.15"));
                parThree = taxThree.multiply(new BigDecimal("-0.15"));
                parFour = taxFour.multiply(new BigDecimal("-0.15"));
                parFive = taxFive.multiply(new BigDecimal("-0.15"));
            } else if (par.getValue() == InvestmentParEnum.WORKING_CAPITAL.getValue()) {

            } else if (par.getValue() == InvestmentParEnum.LIQUIDATION.getValue()) {

            }
            item.put("parZero", parZero);
            item.put("parOne", parOne);
            item.put("parTwo", parTwo);
            item.put("parThree", parThree);
            item.put("parFour", parFour);
            item.put("parFive", parFive);
            parList.add(item);
        }
        List<Map<String, Object>> sortParList = parList.stream().sorted(Comparator.comparing((Map<String, Object> h) -> (Integer) h.get("sort"))).collect(Collectors.toList());

        parMap.put("parList", sortParList);
        dataMap.put("parMap", parMap);

        return dataMap;
    }

    /**
     * 计算 invoiced
     *
     * @param supplyPrice 零售价
     * @param rebate      规模扣
     * @param sales       销量
     * @return invoiced
     */
    private BigDecimal calculateInvoiced(BigDecimal supplyPrice, BigDecimal rebate, BigDecimal sales) {
        if (BigDecimal.ZERO.compareTo(sales) == 0) {
            return BigDecimal.ZERO;
        }
        BigDecimal invoicedSales = supplyPrice.multiply(BigDecimal.ONE.subtract(rebate)).divide(new BigDecimal("1.13"), 6, RoundingMode.HALF_UP).multiply(sales);
        return invoicedSales;
    }

    /**
     * 计算 cm
     *
     * @param invoicedSales     invoicedSales
     * @param cashDeduction     现金扣
     * @param discountedSupport 折扣支持
     * @param sales             销量
     * @param profitParam       profitParam
     * @return invoiced
     */
    private BigDecimal calculateCm(BigDecimal invoicedSales, BigDecimal cashDeduction, BigDecimal discountedSupport, BigDecimal sales, BigDecimal profitParam) {
        if (BigDecimal.ZERO.compareTo(sales) == 0) {
            return BigDecimal.ZERO;
        }
        BigDecimal cm = invoicedSales.multiply(BigDecimal.ONE.subtract(cashDeduction).subtract(discountedSupport)).subtract(profitParam.multiply(sales)).
                divide(invoicedSales.multiply(BigDecimal.ONE.subtract(cashDeduction).subtract(discountedSupport)), 6, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        return cm;
    }

    /**
     * 计算 Units
     *
     * @param volumeNew     volumeNew
     * @param volumeReplace volumeReplace
     * @return units
     */
    private BigDecimal calculateUnits(BigDecimal volumeNew, BigDecimal volumeReplace) {
        BigDecimal units = volumeNew.subtract(volumeReplace).divide(BigDecimal.valueOf(1000), 6, RoundingMode.HALF_UP);
        return units;
    }

    /**
     * 计算 NIS
     *
     * @param salesNew     salesNew
     * @param salesReplace salesReplace
     * @return nis
     */
    private BigDecimal calculateNIS(BigDecimal salesNew, BigDecimal salesReplace) {
        BigDecimal nis = salesNew.subtract(salesReplace).divide(BigDecimal.valueOf(1000), 6, RoundingMode.HALF_UP);
        return nis;
    }

    /**
     * 计算 per units
     *
     * @param units units
     * @param nis   nis
     * @return perUnits
     */
    private BigDecimal calculatePerUnits(BigDecimal units, BigDecimal nis) {
        if (BigDecimal.ZERO.compareTo(units) == 0) {
            return BigDecimal.ZERO;
        }
        BigDecimal perUnits = nis.divide(units, 6, RoundingMode.HALF_UP);
        return perUnits;
    }

    /**
     * 计算 VIP
     *
     * @param vipNew     vipNew
     * @param vipReplace vipReplace
     * @return vip
     */
    private BigDecimal calculateVip(BigDecimal vipNew, BigDecimal vipReplace) {
        BigDecimal vip = vipNew.subtract(vipReplace).divide(BigDecimal.valueOf(1000), 6, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(-1));
        return vip;
    }

    /**
     * 计算 Net Sales
     *
     * @param nis      nis
     * @param vip      vip
     * @param discount discount
     * @return vip
     */
    private BigDecimal calculateNetSales(BigDecimal nis, BigDecimal vip, BigDecimal discount) {
        BigDecimal netSales = nis.add(vip).add(discount);
        return netSales;
    }

    /**
     * 计算  Sales loss
     *
     * @param netSales netSales
     * @param lossRate lossRate
     * @return salesCommissions
     */
    private BigDecimal calculateSalesLoss(BigDecimal netSales, BigDecimal lossRate) {
        BigDecimal loss = netSales.multiply(lossRate).divide(BigDecimal.valueOf(-100), 6, RoundingMode.HALF_UP);
        return loss;
    }

    /**
     * 计算  Actual Contribution rate
     *
     * @param netSales     netSales
     * @param contribution contribution
     * @return Actual Contribution rate
     */
    private BigDecimal calculateContributionRate(BigDecimal netSales, BigDecimal contribution) {
        if (BigDecimal.ZERO.compareTo(netSales) == 0) {
            return BigDecimal.ZERO;
        }
        BigDecimal rate = netSales.divide(contribution, 6, RoundingMode.HALF_UP);
        return rate;
    }

    /**
     * 计算 rate
     *
     * @param param       param
     * @param divideParam divideParam
     * @return rate
     */
    private BigDecimal calculateRate(BigDecimal param, BigDecimal divideParam) {
        if (BigDecimal.ZERO.compareTo(divideParam) == 0) {
            return new BigDecimal(0);
        }
        BigDecimal rate = param.multiply(BigDecimal.valueOf(-100)).divide(divideParam, 6, RoundingMode.HALF_UP);
        return rate;
    }

    /**
     * 计算 Day Amount
     *
     * @param amount amount
     * @param days   days
     * @return dayAmount
     */
    private BigDecimal calculateDayAmount(BigDecimal amount, BigDecimal days) {
        BigDecimal dayAmount = amount.multiply(days).divide(new BigDecimal("360"), 6, RoundingMode.HALF_UP);
        return dayAmount;
    }

    /**
     * 计算 -/1000
     *
     * @param param param
     * @return result
     */
    private BigDecimal calculateThousandNegative(BigDecimal param) {
        BigDecimal result = param.multiply(new BigDecimal(-1)).divide(new BigDecimal(1000),6,RoundingMode.HALF_UP);
        return result;
    }

    /**
     * 获取测算原始数据
     *
     * @param id 测算id
     * @return 测算原始数据
     */
    private CalculateDataDto getCalculateData(String id) {
        CalculateDataDto calculateDataDto = new CalculateDataDto();
        calculateDataDto.setId(id);
        // basicData
        AssetsInvestment assetsInvestment = assetsInvestmentDao.selectById(id);
        calculateDataDto.setBasicData(assetsInvestment);
        // productData
        Map<String, Object> queryParam = new HashMap<>();
        queryParam.put("investmentId", id);
        queryParam.put("startNum", 0);
        queryParam.put("pageSize", 10000);
        List<InvestmentProduct> allProductList = assetsInvestmentProductDao.pageInvestmentProductInfo(queryParam);
        List<InvestmentProduct> newProductList = new ArrayList<>();
        List<InvestmentProduct> replaceProductList = new ArrayList<>();
        for (InvestmentProduct product : allProductList) {
            if (product.getType() == 1) {
                newProductList.add(product);
            } else if (product.getType() == 2) {
                replaceProductList.add(product);
            }
        }
        calculateDataDto.setNewProductData(newProductList);
        calculateDataDto.setReplaceProductData(replaceProductList);

        // investData
        List<InvestmentInput> inputList = assetsInvestmentInputDao.pageInvestmentInputInfo(queryParam);
        calculateDataDto.setInvestData(inputList);

        // otherExpensesData
        List<InvestmentOtherExpenses> expensesList = assetsInvestmentOtherExpensesDao.pageInvestmentOtherExpensesInfo(queryParam);

        calculateDataDto.setExpensesData(expensesList);

        // lossRateData
        List<InvestmentLossRate> lossRateList = assetsInvestmentLossRateDao.pageInvestmentLossRateInfo(queryParam);
        calculateDataDto.setLossRateData(lossRateList);

        // turnoverData
        List<InvestmentTurnover> turnoverList = assetsInvestmentTurnoverDao.pageInvestmentTurnoverInfo(queryParam);
        calculateDataDto.setTurnoverData(turnoverList);

        return calculateDataDto;
    }

    /**
     * 修改数据
     *
     * @param calculateDataDto 测算数据
     * @return 测算数据id
     */
    private String modifyInvestmentInfo(CalculateDataDto calculateDataDto) {
        User currentUser = (User) ThreadlocalUtils.getCache(ThreadLocalConstants.USER_INFO);
        String currentTime = TimeUtils.getDate(TimeFormatConstants.YYYY_MM_DD_HH_MM_SS);
        String id = calculateDataDto.getId();

        // 基本信息
        AssetsInvestment basicDb = assetsInvestmentDao.selectById(id);
        AssetsInvestment basicData = calculateDataDto.getBasicData();
        basicData.setCreateUser(basicDb.getCreateUser());
        basicData.setCreateTime(basicDb.getCreateTime());
        basicData.setUpdateUser(currentUser.getId());
        basicData.setUpdateTime(currentTime);
        basicData.setStatus(basicDb.getStatus());
        assetsInvestmentDao.updateById(basicData);

        // 产品信息
        assetsInvestmentProductDao.deleteByInvestmentId(id);
        List<InvestmentProduct> productList = new ArrayList<>();
        List<InvestmentProduct> newProductList = calculateDataDto.getNewProductData();
        if (ObjectUtils.isEmpty(newProductList)) {
            throw new AosException(ReturnCodes.HTTP_PARAM_ERROR, "新产品信息不能为空！");
        }
        for (InvestmentProduct newProduct : newProductList) {
            newProduct.setType(1);
            newProduct.setId(SnowFlake.nextIdStr());
            newProduct.setInvestmentId(id);
            newProduct.setCreateUser(currentUser.getId());
            newProduct.setCreateTime(currentTime);
            productList.add(newProduct);
        }
        List<InvestmentProduct> replaceProductList = calculateDataDto.getReplaceProductData();
        for (InvestmentProduct replaceProduct : replaceProductList) {
            replaceProduct.setType(2);
            replaceProduct.setId(SnowFlake.nextIdStr());
            replaceProduct.setInvestmentId(id);
            replaceProduct.setCreateUser(currentUser.getId());
            replaceProduct.setCreateTime(currentTime);
            productList.add(replaceProduct);
        }
        assetsInvestmentProductDao.insertBatch(productList);

        // 固资投入
        assetsInvestmentInputDao.deleteByInvestmentId(id);
        List<InvestmentInput> investInputList = calculateDataDto.getInvestData();
        if (!ObjectUtils.isEmpty(investInputList)) {
            List<InvestmentInput> addInputList = new ArrayList<>();
            for (InvestmentInput investmentInput : investInputList) {
                investmentInput.setId(SnowFlake.nextIdStr());
                investmentInput.setInvestmentId(id);
                addInputList.add(investmentInput);
            }
            if (!ObjectUtils.isEmpty(addInputList)) {
                assetsInvestmentInputDao.insertBatch(addInputList);
            }
        }

        // 其他一次性支出
        assetsInvestmentOtherExpensesDao.deleteByInvestmentId(id);
        List<InvestmentOtherExpenses> investExpensesList = calculateDataDto.getExpensesData();
        if (!ObjectUtils.isEmpty(investExpensesList)) {
            List<InvestmentOtherExpenses> addExpensesList = new ArrayList<>();
            for (InvestmentOtherExpenses expenses : investExpensesList) {
                expenses.setId(SnowFlake.nextIdStr());
                expenses.setInvestmentId(id);
                addExpensesList.add(expenses);
            }
            if (!ObjectUtils.isEmpty(addExpensesList)) {
                assetsInvestmentOtherExpensesDao.insertBatch(addExpensesList);
            }
        }

        // 损益费率
        assetsInvestmentLossRateDao.deleteByInvestmentId(id);
        List<InvestmentLossRate> lossRateList = calculateDataDto.getLossRateData();
        if (!ObjectUtils.isEmpty(lossRateList)) {
            List<InvestmentLossRate> addLossRateList = new ArrayList<>();
            for (InvestmentLossRate lossRate : lossRateList) {
                lossRate.setId(SnowFlake.nextIdStr());
                lossRate.setInvestmentId(id);
                addLossRateList.add(lossRate);
            }
            if (!ObjectUtils.isEmpty(addLossRateList)) {
                assetsInvestmentLossRateDao.insertBatch(addLossRateList);
            }
        }

        // 周转天数
        assetsInvestmentTurnoverDao.deleteByInvestmentId(id);
        List<InvestmentTurnover> turnoverList = calculateDataDto.getTurnoverData();
        if (!ObjectUtils.isEmpty(turnoverList)) {
            List<InvestmentTurnover> addTurnoverList = new ArrayList<>();
            for (InvestmentTurnover turnover : turnoverList) {
                turnover.setId(SnowFlake.nextIdStr());
                turnover.setInvestmentId(id);
                addTurnoverList.add(turnover);
            }
            if (!ObjectUtils.isEmpty(addTurnoverList)) {
                assetsInvestmentTurnoverDao.insertBatch(addTurnoverList);
            }
        }
        return calculateDataDto.getId();
    }

    private Map<String, Object> calculateProduct(InvestmentProduct investmentProduct) {
        Map<String, Object> productMap = ObjectUtils.object2Map(investmentProduct);

        // 规模扣 %转换
        BigDecimal rebate = new BigDecimal(investmentProduct.getRebate()).divide(BigDecimal.valueOf(100), 6, RoundingMode.HALF_UP);
        // 服务转安装 %转换
        BigDecimal serviceInstallDef = new BigDecimal(investmentProduct.getServiceInstall()).divide(BigDecimal.valueOf(100), 6, RoundingMode.HALF_UP);
        // 返利+现金扣 %转换
        BigDecimal cashDeduction = new BigDecimal(investmentProduct.getCashDeduction()).divide(BigDecimal.valueOf(100), 6, RoundingMode.HALF_UP);
        // 折扣性支持 %转换
        BigDecimal discountedSupport = new BigDecimal(investmentProduct.getDiscountedSupport()).divide(BigDecimal.valueOf(100), 6, RoundingMode.HALF_UP);
        // Invoiced sales
        BigDecimal supplyPrice = new BigDecimal(investmentProduct.getSupplyPrice());

        BigDecimal salesOne = new BigDecimal(investmentProduct.getSalesOne());
        BigDecimal invoicedSalesOne = calculateInvoiced(supplyPrice, rebate, salesOne);
        productMap.put("invoicedSalesOne", invoicedSalesOne);
        BigDecimal salesTwo = new BigDecimal(investmentProduct.getSalesTwo());
        BigDecimal invoicedSalesTwo = calculateInvoiced(supplyPrice, rebate, salesTwo);
        productMap.put("invoicedSalesTwo", invoicedSalesTwo);
        BigDecimal salesThree = new BigDecimal(investmentProduct.getSalesThree());
        BigDecimal invoicedSalesThree = calculateInvoiced(supplyPrice, rebate, salesThree);
        productMap.put("invoicedSalesThree", invoicedSalesThree);
        BigDecimal salesFour = new BigDecimal(investmentProduct.getSalesFour());
        BigDecimal invoicedSalesFour = calculateInvoiced(supplyPrice, rebate, salesFour);
        productMap.put("invoicedSalesFour", invoicedSalesFour);
        BigDecimal salesFive = new BigDecimal(investmentProduct.getSalesFive());
        BigDecimal invoicedSalesFive = calculateInvoiced(supplyPrice, rebate, salesFive);
        productMap.put("invoicedSalesFive", invoicedSalesFive);

        // 成本
//        BigDecimal cost = new BigDecimal(investmentProduct.getCost());
//        productMap.put("costOne", cost);
//        productMap.put("costTwo", cost);
//        productMap.put("costThree", cost);
//        productMap.put("costFour", cost);
//        productMap.put("costFive", cost);
        BigDecimal costOne = new BigDecimal(investmentProduct.getCostOne());
        productMap.put("costOne", costOne);
        BigDecimal costTwo = new BigDecimal(investmentProduct.getCostTwo());
        productMap.put("costTwo", costTwo);
        BigDecimal costThree = new BigDecimal(investmentProduct.getCostThree());
        productMap.put("costThree", costThree);
        BigDecimal costFour = new BigDecimal(investmentProduct.getCostFour());
        productMap.put("costFour", costFour);
        BigDecimal costFive = new BigDecimal(investmentProduct.getCostFive());
        productMap.put("costFive", costFive);

        // 净售价
        BigDecimal sellingPrice = supplyPrice.multiply(BigDecimal.ONE.subtract(rebate)).divide(new BigDecimal("1.13"), 6, RoundingMode.HALF_UP).multiply(BigDecimal.ONE.subtract(cashDeduction).subtract(discountedSupport));
        productMap.put("sellingPrice", sellingPrice);

        // odc
        //todo cost区分年度
        BigDecimal otherSupplements = new BigDecimal(investmentProduct.getOtherSupplements());
        BigDecimal taxes = BigDecimal.ZERO.compareTo(otherSupplements) == 0 ? BigDecimal.ZERO : sellingPrice.subtract(costOne).multiply(BigDecimal.valueOf(0.13)).multiply(BigDecimal.valueOf(0.12));
        productMap.put("taxes", taxes);
        BigDecimal serviceInstall = BigDecimal.ZERO.compareTo(otherSupplements) == 0 ? BigDecimal.ZERO :
                supplyPrice.multiply(BigDecimal.ONE.subtract(rebate))
                        .divide(new BigDecimal("1.13"), 6, RoundingMode.HALF_UP)
                        .multiply(serviceInstallDef);
        productMap.put("serviceInstall", serviceInstall);

        // 毛利
        BigDecimal partiallyFilled = new BigDecimal(investmentProduct.getPartiallyFilled());
        BigDecimal freight = new BigDecimal(investmentProduct.getFreight());
        BigDecimal profitParamOne = otherSupplements.add(partiallyFilled).add(taxes).add(serviceInstall).add(freight).add(costOne);
        BigDecimal cmOne = calculateCm(invoicedSalesOne, cashDeduction, discountedSupport, salesOne, profitParamOne);
        productMap.put("cmOne", cmOne);
        BigDecimal profitParamTwo = otherSupplements.add(partiallyFilled).add(taxes).add(serviceInstall).add(freight).add(costTwo);
        BigDecimal cmTwo = calculateCm(invoicedSalesTwo, cashDeduction, discountedSupport, salesTwo, profitParamTwo);
        productMap.put("cmTwo", cmTwo);
        BigDecimal profitParamThree = otherSupplements.add(partiallyFilled).add(taxes).add(serviceInstall).add(freight).add(costThree);
        BigDecimal cmThree = calculateCm(invoicedSalesThree, cashDeduction, discountedSupport, salesThree, profitParamThree);
        productMap.put("cmThree", cmThree);
        BigDecimal profitParamFour = otherSupplements.add(partiallyFilled).add(taxes).add(serviceInstall).add(freight).add(costFour);
        BigDecimal cmFour = calculateCm(invoicedSalesFour, cashDeduction, discountedSupport, salesFour, profitParamFour);
        productMap.put("cmFour", cmFour);
        BigDecimal profitParamFive = otherSupplements.add(partiallyFilled).add(taxes).add(serviceInstall).add(freight).add(costFive);
        BigDecimal cmFive = calculateCm(invoicedSalesFive, cashDeduction, discountedSupport, salesFive, profitParamFive);
        productMap.put("cmFive", cmFive);

        //  Volume
        productMap.put("volumeOne", salesOne);
        productMap.put("volumeTwo", salesTwo);
        productMap.put("volumeThree", salesThree);
        productMap.put("volumeFour", salesFour);
        productMap.put("volumeFive", salesFive);

        // Cost
        BigDecimal costYOne = salesOne.multiply(costOne);
        productMap.put("costYOne", costYOne);
        BigDecimal costYTwo = salesTwo.multiply(costTwo);
        productMap.put("costYTwo", costYTwo);
        BigDecimal costYThree = salesThree.multiply(costThree);
        productMap.put("costYThree", costYThree);
        BigDecimal costYFour = salesFour.multiply(costFour);
        productMap.put("costYFour", costYFour);
        BigDecimal costYFive = salesFive.multiply(costFive);
        productMap.put("costYFive", costYFive);

        //  VIP
        BigDecimal vipOne = invoicedSalesOne.multiply(cashDeduction);
        productMap.put("vipOne", vipOne);
        BigDecimal vipTwo = invoicedSalesTwo.multiply(cashDeduction);
        productMap.put("vipTwo", vipTwo);
        BigDecimal vipThree = invoicedSalesThree.multiply(cashDeduction);
        productMap.put("vipThree", vipThree);
        BigDecimal vipFour = invoicedSalesFour.multiply(cashDeduction);
        productMap.put("vipFour", vipFour);
        BigDecimal vipFive = invoicedSalesFive.multiply(cashDeduction);
        productMap.put("vipFive", vipFive);

        //  Expense   discount
        BigDecimal discountOne = invoicedSalesOne.multiply(discountedSupport);
        productMap.put("discountOne", discountOne);
        BigDecimal discountTwo = invoicedSalesTwo.multiply(discountedSupport);
        productMap.put("discountTwo", discountTwo);
        BigDecimal discountThree = invoicedSalesThree.multiply(discountedSupport);
        productMap.put("discountThree", discountThree);
        BigDecimal discountFour = invoicedSalesFour.multiply(discountedSupport);
        productMap.put("discountFour", discountFour);
        BigDecimal discountFive = invoicedSalesFive.multiply(discountedSupport);
        productMap.put("discountFive", discountFive);

        //  ODC
        BigDecimal paramTwo = otherSupplements.add(partiallyFilled).add(taxes).add(serviceInstall);
        BigDecimal odcOne = salesOne.multiply(paramTwo);
        productMap.put("odcOne", odcOne);
        BigDecimal odcTwo = salesTwo.multiply(paramTwo);
        productMap.put("odcTwo", odcTwo);
        BigDecimal odcThree = salesThree.multiply(paramTwo);
        productMap.put("odcThree", odcThree);
        BigDecimal odcFour = salesFour.multiply(paramTwo);
        productMap.put("odcFour", odcFour);
        BigDecimal odcFive = salesFive.multiply(paramTwo);
        productMap.put("odcFive", odcFive);

        //  Freight freight
        BigDecimal freightOne = salesOne.multiply(freight);
        productMap.put("freightOne", freightOne);
        BigDecimal freightTwo = salesTwo.multiply(freight);
        productMap.put("freightTwo", freightTwo);
        BigDecimal freightThree = salesThree.multiply(freight);
        productMap.put("freightThree", freightThree);
        BigDecimal freightFour = salesFour.multiply(freight);
        productMap.put("freightFour", freightFour);
        BigDecimal freightFive = salesFive.multiply(freight);
        productMap.put("freightFive", freightFive);

        return productMap;
    }

    private Map<String, Object> calculateProfit() {
        Map<String, Object> profitMap = new HashMap<>();
//        for() {
//
//        }
        return profitMap;
    }

    /**
     * 计算Depreciation
     *
     * @param investmentInputList 固资投入列表
     * @return Depreciation结果
     */
    private Map<String, Object> calculateDepreciation(List<InvestmentInput> investmentInputList) {
        Map<String, Object> depreciationMap = new HashMap<>();
        List<Map<String, Object>> bookList = new ArrayList<>(investmentInputList.size());
        List<Map<String, Object>> taxList = new ArrayList<>(investmentInputList.size());
        // 获取资产寿命配置
        Map<String, Object> queryParam = new HashMap<>();
        queryParam.put("configType", InvestmentConfigTypeEnum.TYPE_LIFESPAN.getValue() - 4);
//        queryParam.put("status", 1);
        queryParam.put("startNum", 0);
        queryParam.put("pageSize", 10000);

        List<AssetsInvestmentConfig> investmentConfigList = investmentConfigDao.pageInvestmentConfigInfo(queryParam);
        Map<String, AssetsInvestmentConfig> assetsTypeMap = new HashMap<>();
        for (AssetsInvestmentConfig investmentConfig : investmentConfigList) {
            assetsTypeMap.put(String.valueOf(investmentConfig.getConfigAssetsType()), investmentConfig);
        }
        // totalAmount
        BigDecimal totalAmount = BigDecimal.ZERO;
        // book汇总数据
        Map<String, Object> bookSummaryMap = new HashMap<>();
        BigDecimal bookAnnualTotal = BigDecimal.ZERO;
        BigDecimal bookDepOneTotal = BigDecimal.ZERO;
        BigDecimal bookDepTwoTotal = BigDecimal.ZERO;
        BigDecimal bookDepThreeTotal = BigDecimal.ZERO;
        BigDecimal bookDepFourTotal = BigDecimal.ZERO;
        BigDecimal bookDepFiveTotal = BigDecimal.ZERO;
        BigDecimal bookDepSixTotal = BigDecimal.ZERO;
        BigDecimal bookDepSevenTotal = BigDecimal.ZERO;
        BigDecimal bookDepEightTotal = BigDecimal.ZERO;
        BigDecimal bookDepNineTotal = BigDecimal.ZERO;
        BigDecimal bookDepTenTotal = BigDecimal.ZERO;
        // tax汇总数据
        Map<String, Object> taxSummaryMap = new HashMap<>();
        BigDecimal taxAnnualTotal = BigDecimal.ZERO;
        BigDecimal taxDepOneTotal = BigDecimal.ZERO;
        BigDecimal taxDepTwoTotal = BigDecimal.ZERO;
        BigDecimal taxDepThreeTotal = BigDecimal.ZERO;
        BigDecimal taxDepFourTotal = BigDecimal.ZERO;
        BigDecimal taxDepFiveTotal = BigDecimal.ZERO;
        BigDecimal taxDepSixTotal = BigDecimal.ZERO;
        BigDecimal taxDepSevenTotal = BigDecimal.ZERO;
        BigDecimal taxDepEightTotal = BigDecimal.ZERO;
        BigDecimal taxDepNineTotal = BigDecimal.ZERO;
        BigDecimal taxDepTenTotal = BigDecimal.ZERO;

        for (InvestmentInput input : investmentInputList) {
            // bookItem
            Map<String, Object> bookItem = ObjectUtils.object2Map(input);
            if (!assetsTypeMap.containsKey(input.getAssetsType())) {
                throw new AosException(ReturnCodes.HTTP_PARAM_ERROR, "资产寿命未配置！");
            }
            bookItem.put("assetsTypeName", AssetsCategoryTypeEnum.getNameByValue(Integer.valueOf(input.getAssetsType())));
            AssetsInvestmentConfig lifeConfig = assetsTypeMap.get(input.getAssetsType());
            BigDecimal bookLife = new BigDecimal(lifeConfig.getParamOne());
            BigDecimal inputAmount = input.getInputAmount();
            totalAmount = totalAmount.add(inputAmount);
            bookItem.put("propertyLife", bookLife);
            BigDecimal bookDepAmount = inputAmount.divide(bookLife, 6, RoundingMode.HALF_UP);
            BigDecimal bookAnnual = BigDecimal.ZERO.equals(inputAmount) ? BigDecimal.ZERO : bookDepAmount;
            bookAnnualTotal = bookAnnualTotal.add(bookAnnual);
            bookItem.put("annualDep", bookAnnual);
            BigDecimal bookDepOne = bookLife.compareTo(BigDecimal.ONE) < 0 ? BigDecimal.ZERO : bookDepAmount;
            bookDepOneTotal = bookDepOneTotal.add(bookDepOne);
            bookItem.put("depOne", bookDepOne);
            BigDecimal bookDepTwo = bookLife.compareTo(BigDecimal.valueOf(2)) < 0 ? BigDecimal.ZERO : bookDepAmount;
            bookDepTwoTotal = bookDepTwoTotal.add(bookDepTwo);
            bookItem.put("depTwo", bookDepTwo);
            BigDecimal bookDepThree = bookLife.compareTo(BigDecimal.valueOf(3)) < 0 ? BigDecimal.ZERO : bookDepAmount;
            bookDepThreeTotal = bookDepThreeTotal.add(bookDepThree);
            bookItem.put("depThree", bookDepThree);
            BigDecimal bookDepFour = bookLife.compareTo(BigDecimal.valueOf(4)) < 0 ? BigDecimal.ZERO : bookDepAmount;
            bookDepFourTotal = bookDepFourTotal.add(bookDepFour);
            bookItem.put("depFour", bookDepFour);
            BigDecimal bookDepFive = bookLife.compareTo(BigDecimal.valueOf(5)) < 0 ? BigDecimal.ZERO : bookDepAmount;
            bookDepFiveTotal = bookDepFiveTotal.add(bookDepFive);
            bookItem.put("depFive", bookDepFive);
            BigDecimal bookDepSix = bookLife.compareTo(BigDecimal.valueOf(6)) < 0 ? BigDecimal.ZERO : bookDepAmount;
            bookDepSixTotal = bookDepSixTotal.add(bookDepSix);
            bookItem.put("depSix", bookDepSix);
            BigDecimal bookDepSeven = bookLife.compareTo(BigDecimal.valueOf(7)) < 0 ? BigDecimal.ZERO : bookDepAmount;
            bookDepSevenTotal = bookDepSevenTotal.add(bookDepSeven);
            bookItem.put("depSeven", bookDepSeven);
            BigDecimal bookDepEight = bookLife.compareTo(BigDecimal.valueOf(8)) < 0 ? BigDecimal.ZERO : bookDepAmount;
            bookDepEightTotal = bookDepEightTotal.add(bookDepEight);
            bookItem.put("depEight", bookDepEight);
            BigDecimal bookDepNine = bookLife.compareTo(BigDecimal.valueOf(9)) < 0 ? BigDecimal.ZERO : bookDepAmount;
            bookDepNineTotal = bookDepNineTotal.add(bookDepNine);
            bookItem.put("depNine", bookDepNine);
            BigDecimal bookDepTen = bookLife.compareTo(BigDecimal.valueOf(10)) < 0 ? BigDecimal.ZERO : bookDepAmount;
            bookDepTenTotal = bookDepTenTotal.add(bookDepTen);
            bookItem.put("depTen", bookDepTen);
            bookList.add(bookItem);
            // taxItem
            Map<String, Object> taxItem = ObjectUtils.object2Map(input);
            taxItem.put("assetsTypeName", AssetsCategoryTypeEnum.getNameByValue(Integer.valueOf(input.getAssetsType())));
            BigDecimal taxLife = new BigDecimal(lifeConfig.getParamTwo());
            taxItem.put("propertyLife", taxLife);
            BigDecimal taxDepAmount = inputAmount.divide(taxLife, 6, RoundingMode.HALF_UP);
            BigDecimal taxAnnual = BigDecimal.ZERO.equals(inputAmount) ? BigDecimal.ZERO : taxDepAmount;
            taxAnnualTotal = taxAnnualTotal.add(taxAnnual);
            taxItem.put("annualDep", taxAnnual);
            BigDecimal taxDepOne = taxLife.compareTo(BigDecimal.ONE) < 0 ? BigDecimal.ZERO : taxDepAmount;
            taxDepOneTotal = taxDepOneTotal.add(taxDepOne);
            taxItem.put("depOne", taxDepOne);
            BigDecimal taxDepTwo = taxLife.compareTo(BigDecimal.valueOf(2)) < 0 ? BigDecimal.ZERO : taxDepAmount;
            taxDepTwoTotal = taxDepTwoTotal.add(taxDepTwo);
            taxItem.put("depTwo", taxDepTwo);
            BigDecimal taxDepThree = taxLife.compareTo(BigDecimal.valueOf(3)) < 0 ? BigDecimal.ZERO : taxDepAmount;
            taxDepThreeTotal = taxDepThreeTotal.add(taxDepThree);
            taxItem.put("depThree", taxDepThree);
            BigDecimal taxDepFour = taxLife.compareTo(BigDecimal.valueOf(4)) < 0 ? BigDecimal.ZERO : taxDepAmount;
            taxDepFourTotal = taxDepFourTotal.add(taxDepFour);
            taxItem.put("depFour", taxDepFour);
            BigDecimal taxDepFive = taxLife.compareTo(BigDecimal.valueOf(5)) < 0 ? BigDecimal.ZERO : taxDepAmount;
            taxDepFiveTotal = taxDepFiveTotal.add(taxDepFive);
            taxItem.put("depFive", taxDepFive);
            BigDecimal taxDepSix = taxLife.compareTo(BigDecimal.valueOf(6)) < 0 ? BigDecimal.ZERO : taxDepAmount;
            taxDepSixTotal = taxDepSixTotal.add(taxDepSix);
            taxItem.put("depSix", taxDepSix);
            BigDecimal taxDepSeven = taxLife.compareTo(BigDecimal.valueOf(7)) < 0 ? BigDecimal.ZERO : taxDepAmount;
            taxDepSevenTotal = taxDepSevenTotal.add(taxDepSeven);
            taxItem.put("depSeven", taxDepSeven);
            BigDecimal taxDepEight = taxLife.compareTo(BigDecimal.valueOf(8)) < 0 ? BigDecimal.ZERO : taxDepAmount;
            taxDepEightTotal = taxDepEightTotal.add(taxDepEight);
            taxItem.put("depEight", taxDepEight);
            BigDecimal taxDepNine = taxLife.compareTo(BigDecimal.valueOf(9)) < 0 ? BigDecimal.ZERO : taxDepAmount;
            taxDepNineTotal = taxDepNineTotal.add(taxDepNine);
            taxItem.put("depNine", taxDepNine);
            BigDecimal taxDepTen = taxLife.compareTo(BigDecimal.valueOf(10)) < 0 ? BigDecimal.ZERO : taxDepAmount;
            taxDepTenTotal = taxDepTenTotal.add(taxDepTen);
            taxItem.put("depTen", taxDepTen);
            taxList.add(taxItem);
        }
        // book summary
        bookSummaryMap.put("costTotal", totalAmount);
        bookSummaryMap.put("annualTotal", bookAnnualTotal);
        bookSummaryMap.put("depOneTotal", bookDepOneTotal);
        bookSummaryMap.put("depTwoTotal", bookDepTwoTotal);
        bookSummaryMap.put("depThreeTotal", bookDepThreeTotal);
        bookSummaryMap.put("depFourTotal", bookDepFourTotal);
        bookSummaryMap.put("depFiveTotal", bookDepFiveTotal);
        bookSummaryMap.put("depSixTotal", bookDepSixTotal);
        bookSummaryMap.put("depSevenTotal", bookDepSevenTotal);
        bookSummaryMap.put("depEightTotal", bookDepEightTotal);
        bookSummaryMap.put("depNineTotal", bookDepNineTotal);
        bookSummaryMap.put("depTenTotal", bookDepTenTotal);
        // tax summary
        taxSummaryMap.put("costTotal", totalAmount);
        taxSummaryMap.put("annualTotal", taxAnnualTotal);
        taxSummaryMap.put("depOneTotal", taxDepOneTotal);
        taxSummaryMap.put("depTwoTotal", taxDepTwoTotal);
        taxSummaryMap.put("depThreeTotal", taxDepThreeTotal);
        taxSummaryMap.put("depFourTotal", taxDepFourTotal);
        taxSummaryMap.put("depFiveTotal", taxDepFiveTotal);
        taxSummaryMap.put("depSixTotal", taxDepSixTotal);
        taxSummaryMap.put("depSevenTotal", taxDepSevenTotal);
        taxSummaryMap.put("depEightTotal", taxDepEightTotal);
        taxSummaryMap.put("depNineTotal", taxDepNineTotal);
        taxSummaryMap.put("depTenTotal", taxDepTenTotal);
        depreciationMap.put("depreciationBookList", bookList);
        depreciationMap.put("bookSummary", bookSummaryMap);
        depreciationMap.put("depreciationTaxList", taxList);
        depreciationMap.put("taxSummary", taxSummaryMap);
        depreciationMap.put("totalAmount", totalAmount);
        return depreciationMap;
    }

    private Map<String, Object> calculatePar() {
        Map<String, Object> parMap = new HashMap<>();
        return parMap;
    }
}
